I'm creating a Django model, where (as a simplified example) a user group (Users are all assigned to a group) will be able to access files of a certain file type, and which types a group can access will change by group. The list of files can be any of ~10 common file types. This list might change, but that's probably not common.
Roughly speaking, I see two ways of doing this. Representing the file types as a list of strings for each user [".jpg", ".txt", ".zip"]
or, as a M:M relationship with some sort of "FileExtension" Object.
These are cases in which I imagine the ORM route would be much preferred (Ex: If it's important to keep track of Each file extension's use case as for "image", "text", "audio", etc) But what if there's no other information we really need to consider here but the file extension itself? Is there a reason to create a whole model for just a few strings? In my actual project, I want to avoid the complications of creating and maintaining multiple models and storing those in the DB if I can.
Rough Possible Code Examples of each:
String/List approach:
class UserGroup(models.Model):
group_name = models.CharField(max_length=128)
file_access = models.JSONField(null=True) #JSON-serialized list of strings
Model approach:
class UserGroup(models.Model):
group_name = models.CharField(max_length=128)
file_access = models.ManyToManyField(FileExtension)
class FileExtension(models.Model):
extension = models.CharField(max_length=8, null=True)
Quick Note: I've already looked into this answer which was helpful in showing me the ways I could do this, but does not leave me convinced as to what the best way is for me to do here. Also the question is a decade old so perhaps some things have changed in how Django handles this.