Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
You still can reference the data: class Foo(models.Model): pass class Bar(models.Model): foo = models.ForeignKey(Foo, related_name='bars') f = Foo() b1 = Bar(foo=f) b2 = Bar(foo=f) f.bars.all() # > On 9 Aug 2017, at 18:19, Thomas Hughes wrote: > >

Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Thomas Hughes
Thank you for your reply. I understand your third point. In this application though I have a many images to a single detail structure. For your first point "use `related_name` in your model fields to get pretty backref names (so you don't have to use image_set everywhere)", how do I do that

Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
Whoops, looks like all dots are in place, my mistake. First and last points are still valid, though. > On 9 Aug 2017, at 16:08, Александр Христюхин (roboslone) > wrote: > > Hi, > > First of all, you can use `related_name` in your model fields to get pretty > backref

Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Александр Христюхин (roboslone)
Hi, First of all, you can use `related_name` in your model fields to get pretty backref names (so you don't have to use image_set everywhere). Second, you're missing dots in your template (`for detail in project.projectdetail_set.all`). And finally, your model is called ProjectDetailImage and

Re: How to handle nested backward lookups in a template for a generic detail view?

2017-08-09 Thread Thomas Hughes
Just FYI - the issue was with using 'image.url' rather than 'image.image.url' in code labeled with 'do something with image' in the HTML template above. On Monday, August 7, 2017 at 3:52:15 PM UTC-4, Thomas Hughes wrote: > > I have a generic detail view serving content for 'project' to an HTML

How to handle nested backward lookups in a template for a generic detail view?

2017-08-07 Thread Thomas Hughes
I have a generic detail view serving content for 'project' to an HTML template with the following code: {% for detail in project.projectdetail_set.all %} {% for image in detail.projectdetailimage_set.all %} do something with image {% endfor %} {% endfor %} and my models look