On Sep 15, 9:25 pm, "Lance F. Squire" <[EMAIL PROTECTED]> wrote:
> On Sep 15, 4:13 pm, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > So, putting that all together:
>
> > {% for pic in info.system_pictures.all %}
> >     {% ifequal pic.image_category.name 'Header_Pic' %}
> >         <img ... bla ... >
> >     {% endifequal %}
> > {% endfor %}
>
> Sweet! That works.
> Thanks!
>
> I'll try to remember that.
>
> However, Is there a way I can pull just the specific pictures, rather
> than iterating through all possible images?
>
> Lance

That's what this does: gives you all images that are related to the
instance of System (ie 'info') that you passed. It doesn't give you
all images in the database.

If you need to filter it further, you can do it in the view by using
eg info.system_pictures.filter(height__gte=50) to give you all related
images that have a height greater than 50. Or, probably more useful,
info.system_pictures.filter(image_category__name='Header_Pic') to give
you only the related images with category Header_Pic (note the double
underscores in these lookups).

However, you can't do this directly in the template, as it requires
passing arguments to a function call, and Django's template language
doesn't allow that. Probably the easiest solution, if you know you're
always going to be requesting a certain lookup, is to define a custom
method on the model:

class System(models.Model):
    ... field declarations ...

    def get_header_pic(self):
        return
self.system_pictures.filter(image_category__name='Header_Pic')

and then in the template you can just do {{ info.get_header_pic }}

--
DR.
--~--~---------~--~----~------------~-------~--~----~
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