7
7
7761662019-05-24 14:17:17
Django
776166, 2019-05-24 14:17:17

How to make layered properties of a Django model?

Task: for the model you need to make a ton of properties that are calculated on the fly. Properties can be grouped, and I would like them to be stored in the code as well.
To get something like:

model_instance = ModelType.objects.get(id=9001)
print(model_instance.foo.bar.baz)

where foo.bar.baz is just the nesting of properties.
Or what is the best way to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-05-24
@FulTupFul

Recursively linking a model to itself

class Foo(models.Model):
    nested = models.ForeignKey('self', on_delete=CASCADE)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question