Django’s orm is significantly different from SQL Alchemy.
If you could be more specific - provide more details about what you’re trying to accomplish as the end result - we might be able to offer a more Django-centric solution.
I made this app for my system. Basically customer data is obtained through a “global filter”, this prevents me from writing filter.(tenant=tenant) in all my queries.
Why don’t I override the get_queryset method?
In many places the queries are not lazy, forms, CBV, etc.
I think that manipulating queryset before sql is compiled is a solution.
Using a customized manager is a solution, but I don’t know how to adapt it to my problem.
Using Django ModelForm, the related fields get_queryset will be called at server start (runserver). My custom manager needs to work after middleware is called.
No, that’s not an accurate statement. The instance of your ModelForm is created when the form is created within the view. The get_queryset is called at that time.
At a minimum, you’re confusing two different objects.
A Model ForeignKey field is different from a Form ForeignKey field - yes, it’s easy to get the two confused, but they are different objects. Your first reference is to the Form, the second is to the Model. They are instantiated at two different times for two different purposes.