Opened 5 years ago

Closed 21 months ago

#17494 closed New feature (fixed)

Query Methods

Reported by: Zachary Voase Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: donald.stufft@…, tomek@…, bnafta@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The rationale and idea are expounded in more detail in this django-developers thread: http://groups.google.com/group/django-developers/browse_thread/thread/ad1af7d783317302

The idea is a simple decorator, similar to Python's @classmethod, which applies to a method on a manager and marks it as a query method—that is, a method which should be present not only on the manager, but on all querysets which come from that manager.

Change History (9)

comment:1 Changed 5 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

django-model-utils has a solution to this that was originally from http://paulm.us/post/3717466639/passthroughmanager-for-django

comment:2 Changed 5 years ago by Donald Stufft

Cc: donald.stufft@… added

comment:3 Changed 5 years ago by Zachary Voase

If you take a look at the django-developers thread you'll see I did a similar thing in django-qmixin. The point is, we don't want custom QuerySet subclasses, we want a decorator for methods on the Manager, which Manager.__metaclass__ then uses to dynamically construct a QuerySet subclass.

comment:4 Changed 5 years ago by Donald Stufft

django-model-utils used to dynamically generate Querysets to achieve this, which broke pickling them. I don't however know how it was dynamically generated.

In general I think the idea here is to prevent you from having to define the same method twice which that solution has, you just specify it on the QuerySet, then add it to the PassThroughManager. Same Outcome without the metaclass magic which personally find hard to understand with something that gives the same end result.

comment:5 Changed 5 years ago by Tomek Paczkowski

Cc: tomek@… added

comment:6 Changed 5 years ago by Łukasz Rekucki

Triage Stage: UnreviewedAccepted

This is something definitely worth pursuing. Now we just need a good API we can all agree on. If anyone wants to work on this, please check the thread for different implementation attempts.

Last edited 5 years ago by Łukasz Rekucki (previous) (diff)

comment:7 Changed 21 months ago by Fabio Caritas Barrionuevo da Luz

Cc: bnafta@… added

What is the status of this issue? It is still valid?

comment:8 Changed 21 months ago by Tomek Paczkowski

I'd say this has been addressed by as_manager method of QuerySet, here:
https://docs.djangoproject.com/en/1.7/topics/db/managers/#creating-manager-with-queryset-methods

I'm closing this ticket as fixed. If anyone disagrees, it can always be reopened again.

comment:9 Changed 21 months ago by Tomek Paczkowski

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top