Answer the question
In order to leave comments, you need to log in
How to make a generic function in model.py?
Good day to all. There is a function in model.py that pulls out the picture of the record from the parent if the child does not have one. In addition to the picture, there are other fields that can be pulled out according to the same principle, for example, a city. Whether prompt it is possible to universalize this function and to request through a template with parameters of a necessary field.
def get_image(self):
current = self
while not current.image and current.parent is not None:
current = current.parent
if current.image:
return current.image.url
return None
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question