On Tue, 2006-10-03 at 18:49 +1000, Benjamin Ward wrote: > > Im very new to this so please forgive if this is an obvious question: > > How do you describe these relationships in a model in Django: > > 1) > UserProfile extends User. UserProfile has_a Address. Event has_a > Address. > > Where Address has a common data-structure shared by Event and > UserProfile, but each instance of Address would be unique to it's > parent.
If the uniqueness goes both ways, a OneToOneField is what you want. If only one end is unique (a UserProfile has a single address, but an address can be shared by many UserProfile instances), a ForeignKey field on the UserProfile class does the trick. A ForeignKey field is a one-to-many relationship. > 2) > Event can_have_many Tag. Blog can_have_many Tag. Story can_have_many > Tags. Product can_have_many Tag. > > Where Tag is a common data-structure that could be used to create a > taxonomy of the different models allowing you to group them by their > common Tag(s). Django has a ManyToManyField. All of these fields (OneToOneField, ManyToManyField and ForeignKey) are documented at http://www.djangoproject.com/documentation/model_api/#relationships . Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---