On Oct 28, 7:32 am, Daniel Strasser <[EMAIL PROTECTED]> wrote: > Hello Djangonauts, > > I get a NameError and I don't know why, I'm really getting mad. What I > want to do is to list the number of Lessons a Student has passed. > > My schoolutil/student model looks like this: > > from django.db import models > from schoolutil.lesson.models import * > <snip> > > def LessonHours(self): > l = Lesson.objects.all() > return > len(Lesson.objects.filter(student__email__exact='[EMAIL PROTECTED]')) > > I'm getting the following error: > File "/home/daniel/work/schoolutil/../schoolutil/student/models.py", > line 28, in LessonHours > l = Lesson.objects.all() > NameError: global name 'Lesson' is not defined > > But I _did_ import that (second line of the model). I also tried it > with try...except, and there is no exception when importing > schoolutil.lesson.models. Please note that the object filter in > LessonHours() is not correct. For testing, I've hardcoded an email > address. > > What am I doing wrong?
Well, does your lesson.models file definitely define a class called Lesson? This is why it's a bad idea to do from x import *. You should always import the things you need explicitly, then you can tell what's going wrong. Try doing from schoolutil.lesson.models import Lesson and see if it still goes wrong - or if you get a more informative error message. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---