I think I've got it. Does the below look right and would it run ok with 1000 Items on a page?
test_sql = ((t, t.collectionuser_set.get(user=request.user)) for t in CollectionItem.objects.filter(collection=collection)) for item, useritems in test_sql: print 'Test: %s - %s' % (item.title, useritems.grade) On Oct 22, 9:01 pm, The Danny Bos <danny...@gmail.com> wrote: > Hey there, I want to loop through all items in CollectionItem > (models.py below), build a list of the items, then get > CollectionUser.grade if that exists where (user=request.user) and it's > associated with the item in CollectionItem list. > > eg: > > "Item 1" - "" > "Item 2" - "Grade = 89" > "Item 3" - "" > "Item 4" - "Grade = 5" > "Item 5" - "Grade = 34" > "Item 5" - "" > > Here's my models.py > > class Collection(models.Model): > title = models.CharField(max_length=50, unique=True) > description = models.TextField(blank=True) > > class CollectionItem(models.Model): > collection = models.ForeignKey(Collection) > image = models.ImageField(blank=True, upload_to='temp/') > > class CollectionUser(models.Model): > user = models.ForeignKey(User) > collection_item = models.ForeignKey(CollectionItem, blank=True) > grade = models.CharField(max_length=10) > > Know what I mean? --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---