python - Django models: how to handle conceptually similar ideas and somewhat repetitious elements -


i new django , databases.

suppose trying create database filled information various nobility on time. so, there number of different countries might have "monarch" position, held various people, male , female, @ different times. several countries might call king/queen while perhaps 1 call tsar/tsarina. these fixed. initial impression modeling might

class person(models.model):     sex_choices = (         'm': 'male',         'f': 'female'     )     name = models.charfield(max_length=200)      birthdate = models.datefield()     sex = models.charfield(max_length = 2, choices = sex_choices)      titles = models.manytomanyfield(title, through='titleoccupation')  class country(models.model):     #...  class title(models.model):     country = models.foreignkey(country)     #...   class titleoccupation(models.model):     title = models.foreignkey(title)      date_start = models.datefield()     date_end = models.datefield(null = true, blank=true) 

i'm trying figure out how incorporate uniqueness of country's title while recognizing there many similarities among them. title might represent "monarch of england," , monarch called king if male or queen if female. there might many other countries monarch called king or queen, there unique titles representing same idea other countries well. had thought of including kind of model, position represent monarchy, example, , somehow including choices name prefixes (king, etc.) in there. seems generating more bulk.

class position(model.model):     #...      titles_male = (         'king',         'tsar',         'emperor',         ...     )      titles_female = (         'queen',         'tsarina',         'empress',         ...     ) 

at same time, less awkward option might include male , female name prefix each title. less awkward? maybe result in huge amount of wasted space , time when trying to, say, display person's name.

p = person.objects.get(name='???') p.get_title(p.titles.filter(...)) 

where get_title method in person model looks title's name prefix in either male or female set depending on person's sex. seems equally awkward me.

i have looked of django's localization info insight, couldn't extrapolated of sort of intra-language "localization."


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -