python - Django model with list of items -
i new django , writing simple model of phonebook.
i have object person
, contact
every person can have multiple contacts.
i have 2 approaches of modelling, not sure 1 correct.
first approach:
class contact(models.model): phone_number = models.charfield(max_length=20) name = models.charfield(max_length=100,blank=true) class person(models.model): owner = models.onetoonefield(user,unique=true,primary_key=true) phone_number = models.charfield(max_length=20,unique=true) name = models.charfield(max_length=100,blank=true) contacts = models.manytomanyfield('contact', blank=true)
second approach:
class contact(models.model): possessor = models.foreignkey(person,related_name='possessor') phone_number = models.charfield(max_length=20) name = models.charfield(max_length=100,blank=true) class person(models.model): owner = models.onetoonefield(user,unique=true,primary_key=true) phone_number = models.charfield(max_length=20,unique=true) name = models.charfield(max_length=100,blank=true)
i not sure approach better (and correct?) , later easier make queries.
thanks!
the first allows contact
belong more 1 person
. second allows contact
belong single person
.
Comments
Post a Comment