Answer the question
In order to leave comments, you need to log in
How to call a static method from a Django template without explicitly passing the object from the view?
there is a template (in the common application). the template, in addition to the main content (news, articles ...), displays general information and some blocks (which are formed in other applications). general information (Setting) is available from the website application, personnel (Person) from the staff application
class Setting(models.Model):
sitename = (...)
phone = (...)
email = (...)
@staticmethod
def get_setting():
return Setting.first()
class Person(models.Model):
...
@staticmethod
def get_random():
Person.objects.order_by('?').all()[:2]
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