I am hoping to to build a model for a single table that houses different types of "articles" (for argument's sake).
Each article will have MOSTLY common fields (e.g. title, date etc.) but there are cases where some article types (outside of my control) have slightly different field requirements and respective validation rules . No field will ever hold a particularly large amount of data (~100 char max).
At the moment I'm considering a model that defines all common fields and then has a text field for any unusual fields which can be detailed in XML/JSON:
class Article(models.Model):
owner = models.ForeignKey('User')
title = models.CharField(max_length=20)
published = models.BooleanField()
extra = model.TextField() # XML/JSON here for any unusual fields
created = models.DateField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True, auto_now_add=True)
# ... etc.
I would create django form classes to handle validation as new article types are added but I'm trying to avoid having different tables for different article types.
Is there a commonly accepted way to handle a situation like this or is it largely subjective? Obviously the XML/JSON adds a bit of unfortunate overhead.
Thanks.