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) > <[email protected]> wrote: > > 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 it has a field, that > is named `image`. So you won't be able to get rid of `image.image.url`. > However, you can move your image to ProjectDetail model (add field `image = > models.ImageField(...)`) and use it like so: > > {% for detail in project.projectdetail_set.all %} > <img src="{{ detail.image.url }}"/> > {% endfor %} > >> On 9 Aug 2017, at 15:33, Thomas Hughes <[email protected] >> <mailto:[email protected]>> wrote: >> >> 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 >> 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 like: >> >> class Project(models.Model): >> name = models.CharField(max_length=1000) >> start_date = models.DateField() >> abstract = models.TextField() >> abstract_image = models.ImageField(storage=PROJECT_STORAGE) >> >> def __str__(self): >> return self.name <http://self.name/> >> >> class ProjectDetail(models.Model): >> project = models.ForeignKey(Project, on_delete=models.CASCADE) >> name = models.CharField(max_length=1000) >> text = models.TextField() >> >> def __str__(self): >> return self.name <http://self.name/> >> >> class ProjectDetailImage(models.Model): >> detail = models.ForeignKey(ProjectDetail, on_delete=models.CASCADE) >> image = models.ImageField(storage=PROJECT_STORAGE) >> It looks like generic detail view only arranges for backward lookup on the >> 'project' via .projectdetail_set.all but not on the 'detail' as the HTML for >> .projectdetailimage_set.all just never shows up in the HTML source. I am >> wondering then what is the proper way to handle nested ForeignKeys like >> this, basically like a Book > Section > Chapter structure where a Book has >> several Sections and a Section has several Chapters and Chapters are only >> associated with Sections and Sections are only associated with Books. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] >> <mailto:[email protected]>. >> To post to this group, send email to [email protected] >> <mailto:[email protected]>. >> Visit this group at https://groups.google.com/group/django-users >> <https://groups.google.com/group/django-users>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/aca8ff0e-cf46-407d-9a58-36feb7d76276%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/aca8ff0e-cf46-407d-9a58-36feb7d76276%40googlegroups.com?utm_medium=email&utm_source=footer>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/E9E21E4C-B503-4005-86DA-8FFA5629A85F%40gmail.com. For more options, visit https://groups.google.com/d/optout.

