I\'m trying to find the actual class of a django-model object, when using model-inheritance.
Some code to describe the problem:
class Base(models.mod
Well... My problem was. In a view, I had this principal model, lets say "Big_Model" and there were some "Small_Model" related to "Big_Model". So when I wanted to retrieve all "Small_Model" related to a certain instance of "Big_Model" I did that **_set.all() stuff. But the point is that Small_Model has Child Classes and I wanted, in views.py, to get which child class was each of the Small_Model instances related to. My trick was to define boolean methods in model Small_Model like is_child_1() and is_child_2(). And when it is true, you apply the actual child pointer instead of the Small_Model pointer.
Ok... Thats not clear enough, still I dont have much time to write a good example, so i'll just copy-paste my case here:
class Cache(models.Model):
valor = models.DecimalField(max_digits=9, decimal_places=2, blank= True, null= True)
evento=models.ForeignKey(Evento)
def __unicode__(self):
return u'%s: %s' % (self.evento, self.valor)
class Meta:
verbose_name='Cachê'
verbose_name_plural='Cachês'
def is_cb(self):
try:
self.cache_bilheteria
return True
except self.DoesNotExist:
return False
def is_co(self):
try:
self.cache_outro
return True
except self.DoesNotExist:
return False