when using Multi-table inheritance, how do i know what type is the child? My models :-
class Node(models.Model): title = models.CharField(max_length=200) pub_date = models.DateTimeField('date published', default=datetime.datetime.today()) isfp = models.BooleanField("Show on Frontpage", default=True) def __unicode__(self): return self.title.strip() class Article(Node): Story = models.TextField(blank=True, null=True) class Image(Node): file = models.ImageField(upload_to='pics/', blank=True, null=True) caption = models.TextField(blank=True, null=True) source = models.CharField(max_length=20) text = models.TextField(blank=True, null=True) There will be many more like videos, etc... The reason ive used one parent class is because ill be having a lot more common attributes to it. Now how do i define a method or some way of knowing what child the "Node" contains? so it can be parsed accordingly in the template? Ideally, when presenting the content lists, id like to have everything in a single loop. example : {% for node in nodes %} {% ifequal node.get_type "article" %} -- process layout for article-- {% endifequal %} {% ifequal node.get_type "image" %} ---process layout for image--- {% endifequal %} {% endfor %} One way to do this would be to add a "type" field in Node (the parent) class, but then there is a scope of human error when adding stuff. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---