I am making a site in which user uploads it’s pdf and back of the site we generate audio file for each page and now we want to save it on the database(mysql).
Now the problem starts we have model in django and model have the fields which are for a single input.
for example
class Info(models.Model):
phone_img = models.ImageField(upload_to='pics')
Name = models.CharField(max_length=70)
RAM = models.IntegerField(default= None)
ROM = models.IntegerField(default= None)
Cost = models.IntegerField(default= None)
Link = models.URLField(max_length=250)
Now if we use models.FileField(upload_to='files')
then it will upload files to a files folder but I have several files then how to upload that files, because we can’t create fields for that and if we create fields for that then it’s not fix that the user uploaded pdf have the same no. of pages as we have fields.
2
Answers
Create another model "PhoneIMG" with a ForeignKey to "Info". Then you can have as many files as you want that are connected to the "Info" model.
You need to create another model to store that files and linked that model to your Infor model as ManyToMany field. for example
and then link the model with your Info model as follow
for more information please visit the official documentation