Carlos, Thank you for this!

Your solution is what I am looking for,but for some reason I get an
error message:
"NameError: name 'university' is not defined" <http://dpaste.com/
278024/>

Figuring this could an issue with Python and not Django, i added
university ='' to the top.

The validate command returned the message:
Error: One or more models did not validate:
socialmediacourses.departments: 'university' has a relation with
model , which has either not been installed or is abstract.
socialmediacourses.university: Reverse query name for m2m field
'departments' clashes with field 'departments.university'. Add a
related_name argument to the definition for 'departments'.

what am I doing wrong?

On Nov 21, 4:23 am, Carlos Daniel Ruvalcaba Valenzuela
<clsdan...@gmail.com> wrote:
> 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 
> > athttp://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.

Reply via email to