I have a situation I don´t know how to model correctly. I want every child of a class to be associated with a media object (photo, video or music). I want to know which is the preffered approach to this problem. What I have right now is:
class Something(models.Model):
media = models.ForeignKey(Media)
class Media(models.Model):
title = models.CharField(max_lenght=100)
def get_tiny_object():
pass
def get_big_object():
pass
class Picture(Media):
picture = models.ImageField()
def get_tiny_object():
return ...
...
class Video(Media):
video = models.CharField(max_length=200) #youtube id
...
class Music(Media):
music = ....
You get the idea. ¿Does this work? Should I also record on "Something" what kind of media it is?
EDIT:
The idea behind having a Media class, is that I can render in the templates without knowing which kind of media I´m rendering. get_tiny_object() should return, if it is a picture:
"<img style="width:60px; height: 50px" ...>"
So if I have a foreign key to a media object lets say it's id=4, does django know that it should be fetched from music table, if the object I associated with is of Music kind? Because I´ll have 3 different id=4, one on each table (picture, video and music (and possibly more if the domain changes)).