Sunday, July 14, 2013

Re: Error with Passing a class name as a parameter in a ManyToManyField

You error is in the following line:
    prereq = models.ManyToManyField(Course, blank=True, null=True, through='PreReqToCourse')

To phrase this as a sentence, you're saying that "Many courses can belong to many courses." which doesn't follow. I'm guessing that you're aiming to achieve something more like this:
    prereq = models.ManyToManyField(PreReq, blank=True, null=True, through='PreReqToCourse')

So long as the PreReq model is defined above the Course model, you're golden.

JDB


On Sun, Jul 14, 2013 at 9:02 AM, Charounson Saintilus <charounsons@gmail.com> wrote:
This is my first time using the Django Web Framework and I'm new to the python language, so please bear with me.
I've created a model (i.e. a class) called Course which defines several variables:

class Course(models.Model):
        name = models.CharField(max_length=32)
                                   .
                                   .  
                                   .
                                   .
        prereq = models.ManyToManyField(Course, blank=True, null=True, through='PreReqToCourse')

When I try to serve the files from the local server with, python manage.py runserver, I get the following error:

...
...
prereq = models.ManyToManyField(Course, blank=True, null=True, through='PreReqToCourse')
NameError: name 'Course' is not defined


Any ideas? 

Thanks in advance! 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate