Custom SQL setup in django admin

I am trying to configure a proxy model in django admin. It will be a subset of the original model. Code from models.py:

class MyManager(models.Manager):
    def get_query_set(self):
        return super(MyManager, self).get_query_set().filter(some_column='value')

class MyModel(OrigModel):
    objects = MyManager()
    class Meta:
        proxy = True

Now instead of filter () I need to use a complex SELECT statement with JOINS. How can I fully implement it in the user manager?

+3
source share
2 answers

Django provides an extra () QuerySet modifier - this is the hook for entering certain sentences into SQL generated by the QuerySet.

This can be used in complex cases, possibly with one or more additional queries.

+1

ORM MyModel.objects raw SQL . SQL .

- MyModel(). , .. admin, , , . , , , - raw sql get_query_set.

, Manager.raw admin.

+1

Source: https://habr.com/ru/post/1749289/


All Articles