Thanks for the answer Lemuel :)

I added a get_images method in the (example) Toy model, which returns
a list of the pictures related to it. Which basically just wraps
things up:

def get_images(self):
    images = self.toypicture_set.all()
    return images

Doing a select_related, sounds more efficient though, I'll try it out.

On Oct 2, 6:51 pm, Lemuel Formacil <[EMAIL PROTECTED]> wrote:
> On Sep 29, 2007, at 6:14 PM, Panos Laganakos wrote:
>
>
>
>
>
> > On Sep 28, 12:18 pm, Panos Laganakos <[EMAIL PROTECTED]>
> > wrote:
> >> Having two different models, ie: Toy, ToyPicture.
>
> >> ToyPicture, has a ForeignKey to Toy, so you can define many pictures,
> >> that relate to a specific toy.
>
> >> The question is this: in which way should I make the data available
> >> for viewing?
>
> >> 1. Create list/detail generic views for Toy? That would mean I would
> >> have to create a custom template tag, in order to make the  
> >> ToyPicture,
> >> available at the template level of Toy.
>
> >> 2. Create my own custom views of Toy/ToyPicture.
>
> >> What we should consider best practice, or is there's a completely
> >> different way to do it?
>
> Hi, Panos.
>
> Total newbie here with the same "problem" you have, but I think your  
> ToyPicture objects should already be accessible in your template by  
> doing a 'toypicture_set.all' call to your Toy object.
>
> In the template called by your Toy model's object_detail view, for  
> example, you can do a
>
>         {% for toypicture in object.toypicture_set.all %}
>
> to iterate through the ToyPicture objects.  In my case though, I'm  
> also not so sure if this is a good way (or "the way") for accessing  
> the related objects when using the generic views.  (I hope someone  
> can clarify this.)
>
> > I created a list/detail generic view for Toy, and passed ToyPicture
> > objects, as an extra_context. That seems to work, not sure, how to
> > filter the objects at a URLconf level though, if that's possible, or
> > if I'll have to filter it at a template level.
>
> > Still not sure if this is the *best* way to do it.
>
> Regarding doing a 'filter' on the queryset supplied to generic views,  
> I found this article by Malcolm Tredinnick while searching the 'net  
> for example usage of generic views:
>
> http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-
> generic-views/
>
> In that article he wrote a view to wrap the call to the generic_view  
> and supply a filtered queryset.  (I think it's also a good idea to  
> supply a 'select_related()'ed queryset to your Toy model's  
> object_detail so you don't incur another database hit when accessing  
> the related ToyPicture objects).
>
> HTH,
>
> Lemuel


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to