I'm fairly new to Django. I have a model copy (exam copy of a student), the model copy will contain a student test or exam copy and a mark, usually, i would use a FileField and save the copy to the object, but my problem is that a copy could contain many files (page 1, 2, 3 etc)
I was thinking about using a CharField instead that contains the path to a folder that contains the files for that copy, but I don't have a very good idea on how to do that
and if you have a better way I would for you to share.
here is my model
class VersionCopie(models.Model):
id_version = models.CharField(db_column='id_Version', primary_key=True, max_length=100)
numero_version = models.IntegerField(db_column='numero_Version', blank=True, null=True)
note_copie = models.FloatField(db_column='note_Copie', blank=True, null=True)
emplacement_copie = models.CharField(db_column='emplacement_Copie', max_length=10000, blank=True, null=True)
id_copie = models.ForeignKey('Copie', models.CASCADE, db_column='id_Copie', blank=True, null=True)
i just need to know what kind of path i would save to "emplacement_copie"
Well, I think this is classical one-to-many relation. You have probably already implemented something like that by doing id_copie = models.ForeignKey(...)
You should create separate model, representing just one file and containing reference to your VersionCopie. You can still access all files from VersionCopy model, reference is created implictly (see this link).
Example code:
class VersionCopyFile(models.Model):
file = models.FileField( <your arguments> )
version_copy = models.ForeignKey(VersionCopy, on_delete=models.CASCADE)