I want to store events in a web application with which I am deceived, and I am completely not sure about the advantages and disadvantages of each appropriate approach - using inheritance broadly or more modestly.
Example:
class Event(models.Model):
moment = models.DateTimeField()
class UserEvent(Event):
user = models.ForeignKey(User)
class Meta:
abstract = True
class UserRegistrationEvent(UserEvent):
pass
class UserCancellationEvent(UserEvent):
reason = models.CharField()
It seems to me that I am creating database tables such as crazy. This will require a large number of associations to choose things and may make it difficult to request. But the design seems nice, I think.
Would it be wiser to use a โflatterโ model that just has more fields?
class Event(models.Model):
moment = models.DateTimeField()
user = models.ForeignKey(User, blank=True, null=True)
type = models.CharField()
reason = models.CharField(blank=True, null=True)
Thanks for your comments on this, anyone.
Philip
source
share