django-model-behaviors-example icon indicating copy to clipboard operation
django-model-behaviors-example copied to clipboard

Add support for chained .none()

Open benjaoming opened this issue 12 years ago • 4 comments

You need this to have your querysets fully identical to standard queryset behavior :) Notice there's some change in Django 1.6 that I didn't fully catch up on.

benjaoming avatar Nov 08 '13 18:11 benjaoming

Admittedly I didn't see you were using pass_through_manager -- can you tell me if for instance objects.none().published() already works?

benjaoming avatar Nov 08 '13 18:11 benjaoming

Btw great job, very inspirational

benjaoming avatar Nov 08 '13 18:11 benjaoming

chaining after a call to none() doesn't work with PassthroughManager because it changes to an EmptyQuerySet so it no longer returns our custom QuerySet sub-class. Your commit doesn't necessarily resolve this since you need to wire PassthroughManager.

I think this is better solved by PassthroughManager directly. Without that, I'd focus on making a generic solution by sub-classing PassthroughManager or our base QuerySet, and return a sub-class of EmptyQuerySet that accepts arbitrary chained methods and just returns itself.

kevinastone avatar Nov 08 '13 20:11 kevinastone

PassthroughManager is a nice idea, but I rather don't like the dependency because it's such simple code that it's easy to deal with either by copy-pasting the PassthroughManager itself or just write the QuerySet and the manager explicitly. A rather small bargain to avoid dependencies :)

benjaoming avatar Nov 09 '13 01:11 benjaoming