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
>
> 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
>
> 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].
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/aca8ff0e-cf46-407d-9a58-36feb7d76276%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.