On Sun, Sep 6, 2009 at 1:08 PM, Larry<yuelizh...@gmail.com> wrote: > The question is: WHAT is the easiest way to get a list of Item objects > from the list > of User_Item objects, i.e., instead of returning the user-item > relation, we only return > the items.
instead of defining the User_Item model yourself, you can use a ManyToMany relationship (http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield), then you only have to get a User object, and from there the Items_set. something like this: class User (models.Model): ...user fields... class Item (models.Model): ...item fields... user = models.ManyToManyField (User) ... more fields... then in your view you get the user object however you want, maybe from the logged user, and from there you get the items queryset: @login_required def my_view: u = request.user items = u.item_set.all() If you want some data stored in the intermediate relationship table, define the intermediate model and use the 'through' parameter to the fieldtype (http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.through) -- 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 -~----------~----~----~----~------~----~------~--~---