It Worked :)

Thank you both for the guidance.

Here's the final result in case it will help anyone else 
http://dpaste.com/278230/

On Nov 21, 5:09 pm, Carlos Daniel Ruvalcaba Valenzuela
<clsdan...@gmail.com> wrote:
> The first error is simple, university models is defined after your
> department model, thus is not found, you can define the foreign key as
> a string in the form of "appname.ModelName", so you will define it
> like this:
>
> class departments(models.Model):
>     university = models.ForeignKey("appname.university",
> related_name="departments")
>
> Where appname is the name of the application where the models are
> being defined (the folder where models.py is stored).
>
> About the other problem, it would be good to have a little more
> context on what is socialmediacourses and where is throwing you the
> error, but with the above change should do the trick, just don't
> forget to remove your ManyToMany departments definition on University
> model, that would make the name university.department clash.
>
> Regards,
> Carlos Ruvalcaba
>
>
>
> On Sun, Nov 21, 2010 at 7:10 AM, Bruno Amaral <m...@brunoamaral.eu> wrote:
> > 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 
> > 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