On Sep 15, 8:50 pm, "Lance F. Squire" <[EMAIL PROTECTED]> wrote:
> Using Fedora 8, Django  version 0.96.3
>
> I'm currently trying to pull two specific images from a list of images
> associated with a model.
>
> Currently the Models are like this:
>
> class ImageCat(models.Model):
>     name = models.CharField(maxlength=80)
>
> class Image(models.Model):
>         name = models.CharField(maxlength=80)
>         location = models.URLField()
>         height = models.IntegerField()
>         width = models.IntegerField()
>         image_category = models.ForeignKey('ImageCat')
>
> class System(models.Model):
>         manufacturer = models.ForeignKey('Manufacturer')
>         name = models.CharField(maxlength=80)
>         slug = models.SlugField(prepopulate_from=['name'])
> ... other stuff...
>         system_pictures = models.ManyToManyField('Image')
>
> ImageCat is just a name list, as I may need to add categories in the
> future.
>
> Image doesn't use ImageField as I'm manually uploading the images to
> another server and didn't want to deal with the extra stuff (uploading
> etc)
>
> I'm currently trying to pull 2 images of specific category types in
> the template. Unfortunately, I can't quite grasp how to do this...
> Or weather it would be better to pull them in the View before hand....
>
> I'm currently passing the System fields to the template as 'info'.
>
> I've been trying things like 'info.Image.location' but can't figure
> how to specify the category.
>
> Also tried:
>
> {% for pic in info.Image %}
>     {% ifequal pic.image_category 'Header_Pic' %}
>         <img ... bla ... >
>     {% endifequal %}
> {% endfor %}
>
> But that gets me nothing.
>
> Where am I going wrong?
>
> Lance

The model field that relates System to Image is called
system_pictures, so you need to use that rather than the name of the
Image model. system_pictures gives you a Manager, so you need to call
all() on it (although you omit the brackets since you're in a
template). Finally, image_category will give you a model, not a
string, so you need to refer directly to the name field if you want to
compare it with a string.

So, putting that all together:

{% for pic in info.system_pictures.all %}
    {% ifequal pic.image_category.name 'Header_Pic' %}
        <img ... bla ... >
    {% endifequal %}
{% endfor %}

--
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