Will this display all CollectionTypes even if there is no record for a user in CollectionUserPile? As I'd want to set a default item if there isn't, but still loop through all Types.
d On Oct 20, 1:35 am, Javier Guerra <jav...@guerrag.com> wrote: > On Mon, Oct 19, 2009 at 6:53 AM, The Danny Bos <danny...@gmail.com> wrote: > > > > > > > > > K, I've got one for ya. > > > I've created a new table to handle Users latest "owned" item, how > > would I get this joined data up in my views.py where I'm currently > > just looping through CollectionTypes. Tables and current Query is > > below: > > > models.py > > class CollectionType(models.Model): > > title = models.CharField(max_length=50, unique=True) eg: "Pokemon > > Cards" > > slug = models.SlugField(max_length=50, unique=True) eg: "pokemon > > cards" > > > class CollectionUserPile(models.Model): > > user = models.ForeignKey(User) eg: "Danny" > > collection_item = models.ForeignKey(CollectionItem) eg: "Pokemon Card > > No.12" > > collection_type = models.ForeignKey(CollectionType) eg: "Pokemon > > Cards" > > > views.py > > types = CollectionType.objects.all().order_by('title') > > > So I want to loop through all the CollectionTypes, then in that loop I > > want to display the collection_item data. > > try something like this: > > in the view: > > mypiles = request.user.collectionuserpile_set.order_by(collection_type) > > in the template: > > {% for pile in mypiles %} > {% ifchanged %} {{pile.type}} {% endifchanged %} > {{pile.item}} > {% endfor %} > > -- > Javier --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---