I want to upload multiple files through a ModelForm,with all files to be assigned to a file
field of the Model.I have gone through the docs and I saw an example
Would suggest using an M2M field from Feed
model to FeedFile
model.
Makes it all the more easier while querying for files of a particular Feed
object, which i feel is also the most common usecase for Feed
objects
class Feed(models.Model):
user=models.ForeignKey(User, on_delete=models.CASCADE, related_name='feeds')
text=models.TextField(blank=False, max_length=500)
files=models.ManyToManyField(FeedFile)
class FeedFile(models.Model):
file = models.FileField(upload_to="files/%Y/%m/%d")