On Mon, Oct 19, 2009 at 6:53 AM, The Danny Bos <[email protected]> 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---