tags:

views:

31

answers:

1
class Machine(models.Model):
    name= models.CharField( max_length=120)
    class Meta:
        abstract = True

class Car(Machine):
    speed = models.IntegerField()

class Computer(Machine)
    ram = models.IntegerField()

My question is, how can I understand what type is the Machine model. For instamce I know the incoming query is a children of the Machine model but I also want to know it is a Car submodel.

+1  A: 

I am not sure if I understand your question correctly. If you are trying to find out the type of a given instance you can use the built-in type function.

an_object = Car(name = "foo", speed = 80)
an_object.save()
type(an_object) # <class 'project.app.models.Car'>

Or if you wish to check if an_object is an instance of Car you can use isinstance.

isinstance(an_object, Car) # True
Manoj Govindan