Depends on you requirements, you could have used a Foreign Key to the University on the Department model and marking it as required, thus there cannot be a Department without university and set the related_name property on the ForeignKey to the "departments" so you can access University.departments property for the list of departments.
You may not want this if you only want to have 1 kind of department which will be linked to many universities, but I see this may not be the case, thus your models may end like this: class departments(models.Model): GENDER = ((u'M', u'Male'),(u'F', u'Female'),) university = models.ForeignKey(university, related_name="departments") name = models.CharField(max_length=60) head_name = models.CharField(max_length=60) head_email = models.EmailField(max_length=60) head_gender = models.CharField(max_length=2, choices=GENDER) Regards, Carlos Ruvalcaba On Sat, Nov 20, 2010 at 6:19 PM, Bruno Amaral <m...@brunoamaral.eu> wrote: > I have been trying to create a database for Universities, Departments > and Courses. > > The idea is that a University has many departments, which in turn have > one or more courses. > > So far, this model works: http://dpaste.com/277850/ > > With one caveat, it allows a department to exist without a University > linked to it. > > I am at a loss here, even after reading over all the documentation I > could find on the website, does anyone have an idea on what I am doing > wrong, or where I should look for a solution? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.