Answer the question
In order to leave comments, you need to log in
How to access secondary model records?
There are two related tables.
Using the query
article = TestSplitModel.objects.get(id=article_id)
you can get the serial_number, title and description
how to get all Image records associated with an Article?
class Article(models.Model):
serial_number = models.IntegerField()
title = models.CharField(max_length=100)
description = models.TextField()
image = models.ManyToManyField('Image', blank=True)
class Image(models.Model):
slug = models.SlugField(null=True)
image = models.ImageField(upload_to=generate_filename)
Answer the question
In order to leave comments, you need to log in
The documentation contains many simple and understandable examples.
for image in article.image.all():
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question