Hi 汪晟,

Extending the ORM with a subclass of Query isn't common, and not
documented. Perhaps for extensibility this line of code should use
"self.__class__" but there aren't any guarantees about other parts of the
ORM.

The extensions I created for MySQL only involve the QuerySet layer:
https://django-mysql.readthedocs.io/en/latest/queryset_extensions.html .
Perhaps you can track your customization within a custom QuerySet, and only
"at the last moment", before execution, swap the Query object's class and
compiler. From what I can tell, this should be possible in an iterator()
method, before calling super().

It would help to know your use case. It's possible whatever extension
you're adding can be done outside of Query or Compiler. For an example
using database instrumentation, see my recent post:
https://adamj.eu/tech/2020/07/29/backporting-a-django-orm-feature-with-database-instrumentation/

Thanks,

Adam

On Sat, 5 Sep 2020 at 16:12, 汪晟 <uamr...@gmail.com> wrote:

> Hello Mentors and contributors, I’m a  web site developer , when I use
> Django . I custom a  class < SomeQuery > base on < Query >, and modify it’s
> attribute ‘compiler' to  Another one <OtherSQLCompler> which custom by
> myself,. But when I use  < SomeQuery > in a < Queryset > object, and call
> the method filter() with a params ~Q() ,it will call  the method
> ‘split_exclude’ in  < Query >,
> In the line 1772 in the file <django/db/models/sql/query.py>
>
> # Generate the inner query.
> query = Query(self.model)
>
> The code instance a object by the base class < Query >,  but I want it
> instance a object base on < SomeQuery >
>
> So why we don’t make the code like this query = self.__class__(self.model)
>
> I think that is the correct way .
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/93ef71bd-3fe3-4412-9c1c-886f88cbfaaan%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/93ef71bd-3fe3-4412-9c1c-886f88cbfaaan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0tY-3OqPA%2BxiHdN56z4%3D%2BbTwKHXKfWvMm8x4aw0u1OKw%40mail.gmail.com.

Reply via email to