Is this even possible?
I need to store some documents to be retrieved as json/rest.
A Document has many Sections, and a section has a heading, a body and many Images.
Is there a way I can make a form with this structure?
Publication
|-- Section
|-- Image
|-- Image
|-- Section
|-- Image
|-- Section
|-- Image
|-- Image
|-- Image
My models:
class Publication(models.Model):
title = models.CharField(max_length=64)
class Section(models.Model):
publication = models.ForeignKey(Publication)
heading = models.CharField(max_length=128)
body = models.TextField()
class Image(models.Model):
section = models.ForeignKey(Section)
image = models.ImageField(upload_to='images/')
caption = models.CharField(max_length=64, blank=True)
alt_text = models.CharField(max_length=64)
I can do this relatively easy when Image is related to Publication, because there is only one level of nesting.
When Image is belongs to Section, though, I'm not sure how to build the form.
It seems as though there's no easy way to do this with inline formsets.
Can anyone help?