A
A
Antonio Solo2018-07-22 14:55:47
Django
Antonio Solo, 2018-07-22 14:55:47

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]

Can I call Setting.get_setting and Person.get_random directly (and if so, how?) or do I have to explicitly pass them from the view ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question