I am creating a web app for cloud storage where user can create folders and upload files. I want to create a model for files like:
class upload(models.Model):
files = # array of files which I don't know how to create
title = models.CharField(max_length = 30)
user = models.ForeignKey(User,on_delete=models.CASCADE)
I will be thankful if anyone suggests me how to do so or tell me any other efficient way to upload files and use it.
You need to create another model (e.g. UploadFragment) and bind it with a foreign key relation to your Upload model.
class Upload(models.Model):
title = models.CharField(max_length = 30)
user = models.ForeignKey(User, on_delete=models.CASCADE)
class UploadFragment(models.Model):
file = models.FileField()
upload = models.ForeignKey(Upload, related_name="files", on_delete=models.CASCADE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With