B
B
Bjornie2018-07-24 19:34:35
Django
Bjornie, 2018-07-24 19:34:35

How to get access to model B which is inherited from A?

There is a model A:

class ModelA(models.Model):
   name = models.CharField()

There is model B:
class ModelB(ModelA):
   age = models.IntegerField()

Tell me how to access the fields of ModelB, referring to the object through ModelA, for example: Provided that I cannot edit model A, i.e. change its properties. Thank you.
age = ModelA.objects.get(id=1).age

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-07-24
@Bjornie

ModelA.objects.get(id=1).modelb.age

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question