I need some help with Models architecture
Lets say i have 8 categories
each category have shared fields with each other but also unique fields
for example
category1 can have aa, year, from_field, to, observation
category2 can have aa, from_field, to, security, office
etc
Now i have a file that should be uploaded in one of these categories
so file model has aa and categories fields that must be unique together
categories = [
("1", "..."),
("2", "..."),
("3", "..."),
("4", "..."),
("5", "..."),
("6", "..."),
("7", "..."),
("8", "..."),
("ΑΛΛΟ", "..."),
]
class BaseCategory(models.Model):
name = models.CharField(max_length=100, choices=categories, primary_key=True)
file_upload = models.FileField(upload_to="files/")
observation = models.TextField(max_length=500)
class Meta:
abstract = True
class Category1(BaseCategory):
year = models.IntegerField()
from_field = models.CharField(max_length=100)
to = models.CharField(max_length=100)
class Category2(BaseCategory):
from_field = models.CharField(max_length=100)
to = models.CharField(max_length=100)
office = models.ForeignKey(Office, on_delete=models.SET_NULL, null=True)
security_level = models.ForeignKey(Security, on_delete=models.SET_NULL, null=True)
class File(models.Model):
category = models.ForeignKey(
Category1, choices=categories, on_delete=models.CASCADE, related_name="files"
)
aa = models.CharField(max_length=100)
year = models.IntegerField()
from_field = models.CharField(max_length=100)
to = models.CharField(max_length=100)
office = models.ForeignKey(
Office, on_delete=models.SET_NULL, null=True, related_name="files"
)
security_level = models.ForeignKey(
Security, on_delete=models.SET_NULL, null=True, related_name="files"
)
observation = models.TextField(max_length=500)
file_upload = models.FileField(upload_to="files/")