Hello,
This may be long, but I really need your help. I have a class Asset, which is the base class of another classes (like Photo, Question, Video etc.) Basically its a Multiple Table Inheritance. I need this to get all the post or all the objects of the user. And it does what I want. But I saw that, many were against Multiple Table Inheritance, or if not they discouraged MTI. So, I really need to know that, how much will it matter? Or is there any other way to achieve it. To get all the objects of a User? Please help me decide what to do. If I am not clear, please ask me. I will really appreciate if anyone would guide me through this.
Thank you.
This are my models:
class Asset(models.Model):
user = models.ForeignKey(User, related_name = "user_objects")
likes = models.ManyToManyField(User, through="Like", related_name="Liked_user")
comments = models.ManyToManyField(User, through="Comment", related_name="Commented_user")
timestamp = models.DateTimeField(auto_now = True, auto_now_add= False)
updated = models.DateTimeField(auto_now = False, auto_now_add = True)
class Meta:
ordering = ['-timestamp']
def __unicode__(self):
return self.__class__.__name__
class Like(models.Model):
asset = models.ForeignKey(Asset)
liked_by = models.ForeignKey(User)
liked_time = models.DateTimeField(auto_now = True, auto_now_add = False)
def __unicode__(self):
return "%s likes %s" % (self.liked_by, self.asset)
class Comment(models.Model):
asset = models.ForeignKey(Asset)
comment_by = models.ForeignKey(User)
liked_time = models.DateTimeField(auto_now = True, auto_now_add = False)
def __unicode__(self):
return "%s likes %s" % (self.comment_by, self.asset)
def get_upload_file_name(instance, filename):
return "uploaded_files/%s_%s" %(str(time()).replace('.','_'), filename)
class Album(Asset):
title = models.CharField(max_length=200)
description = models.TextField()
def __unicode__(self):
return self.__class__.__name__
class Picture(Asset):
description = models.TextField()
image = models.ImageField(upload_to=get_upload_file_name)
album = models.ForeignKey(Album, null=True, blank=True, default = None)
def __unicode__(self):
return self.__class__.__name__
class BackgroundImage(Picture):
pass
class ProfilePicture(Picture):
pass
class Tag(models.Model):
title = models.CharField(max_length=40)
description = models.TextField()
def __unicode__(self):
return self.title
class Question(Asset):
title = models.CharField(max_length=200)
description = models.TextField()
tags = models.ManyToManyField(Tag)
def __unicode__(self):
return self.title
class Answer(Asset):
description = models.TextField()
question = models.ForeignKey(Question)
def __unicode__(self):
return self.description