views:

31

answers:

1

i wanted to place the foo/view code below into a property under the Foo model object, but the debug message says 'bar' cannot be found. Why does it work in the views.py, but not work when i place it in models.py( i did remember to import Bar)?

thanks!

foo/models.py

class Foo(models.Model):

title = models.CharField(_(u'Title'), max_length=600)

bar/models.py

class Bar(models.Model):

foo = models.ManyToManyField(Foo)

eg_id = models.PositiveIntegerField(_(u'Example ID'), default=0)

foo/views.py

from django.db.models import Count
qs = Foo.objects.filter(
       bar__eg_id__in=id_list
  ).annotate(
       bar_count=Count('bar')
  ).order_by('bar_count')
A: 

Your Bar class probably hasn't been defined yet in models.py - Try moving it above Foo.

Harold