How would I write a view with a single form to add a new person, and on that same form, be able to add 0 or 1 or 2 or ... 68757857 images of that same person?
Please refer to the code below.
In models.py:
class Person(models.Model):
name = models.CharField(max_length=50)
class Image(models.Model):
person = models.ForeignKey(Person)
image = models.ImageField(upload_to='images/')
In forms.py:
class PersonForm(forms.ModelForm):
class Meta:
model = Product
fields = ['name']
class ImageForm(forms.ModelForm):
class Meta:
model = Image
fields = ['person', 'image']
From what I have seen, formsets are used. I have looked at many examples on SO, read the documentation and I am still confused.
I would appreciate it if someone can provide an example of a views.py that fulfils the specification at the beginning of this question.