Thursday 15 July 2010

Django model relates to two other models -



Django model relates to two other models -

i'm trying build dictionary application , having difficulty model.

now wrote this

class term(models.model): term_text = models.charfield("phrase term text", max_length=100) class definition(models.model): term = models.foreignkey(term) definition_text = models.textfield() class country(models.model): #is right method? #should add together foreginkey both term , definition here?

the problem country. both term , definition should have country field term available in many countries , definition limited countries definition others.

now how country model?

i've tried utilize django-countries model field term , definition limiting me utilize 1 country per object.

what want manytomany relationships on both term , definition. way you'll able phone call my_term.countries , my_definition.countries.

class term(models.model): term_text = models.charfield("phrase term text", max_length=100) country = models.manytomanyfield(country) class definition(models.model): term = models.foreignkey(term) definition_text = models.textfield() country = models.manytomanyfield(country) class country(models.model): # define country model class meta: verbose_name_plural = "countries"

django django-models

No comments:

Post a Comment