Re: Getting specific data from a many to many field.

2008-09-16 Thread Daniel Roseman
On Sep 16, 4:16 pm, "Lance F. Squire" <[EMAIL PROTECTED]> wrote: > On Sep 16, 2:30 am, Daniel Roseman <[EMAIL PROTECTED]> > wrote: > > try: > >     return > > self.system_pictures.filter(image_category__name='Header_Pic')[0] > > except IndexError: > >     pass > > > which will always get the first

Re: Getting specific data from a many to many field.

2008-09-16 Thread R. Gorman
> > > try: > >     return > > self.system_pictures.filter(image_category__name='Header_Pic')[0] > > except IndexError: > >     pass > Make sure you have the indentation set correctly. The second and third line of the posted code should actually be one line. I think the formatting was changed w

Re: Getting specific data from a many to many field.

2008-09-16 Thread R. Gorman
> > try: > >     return > > self.system_pictures.filter(image_category__name='Header_Pic')[0] > > except IndexError: > >     pass > > > which will always get the first related image in that category, and > > silently swallows the error that's thrown if there's no such picture. > > Can't seem to ge

Re: Getting specific data from a many to many field.

2008-09-16 Thread Lance F. Squire
On Sep 16, 2:30 am, Daniel Roseman <[EMAIL PROTECTED]> wrote: > > Sorry, my mistake. filter() always gives you a queryset - because > there might be more than one instance of the related model that fits > the criteria - so you can't jut reference the location/width directly. > The best way is to

Re: Getting specific data from a many to many field.

2008-09-15 Thread Daniel Roseman
On Sep 16, 2:30 am, "Lance F. Squire" <[EMAIL PROTECTED]> wrote: > On Sep 15, 5:21 pm, Daniel Roseman <[EMAIL PROTECTED]> > wrote: > > > 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

Re: Getting specific data from a many to many field.

2008-09-15 Thread Lance F. Squire
On Sep 15, 5:21 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > 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_heade

Re: Getting specific data from a many to many field.

2008-09-15 Thread Daniel Roseman
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' %} > >         > >     {%

Re: Getting specific data from a many to many field.

2008-09-15 Thread Lance F. Squire
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' %} > > {% endifequal %} > {% endfor %} > Sweet! That works. Thanks! I'll try to rememb

Re: Getting specific data from a many to many field.

2008-09-15 Thread Daniel Roseman
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 = mod