use_for_related_fields and filtering results - really a no-go?

3 views
Skip to first unread message

kahless

unread,
Dec 20, 2009, 6:56:34 PM12/20/09
to Django users
hi,
the documentation for use_for_related_fields states that it shouldn't
be used for filtering results:
http://docs.djangoproject.com/en/dev/topics/db/managers/#do-not-filter-away-any-results-in-this-type-of-manager-subclass

i just wanted to know if this advice should always be followed (or
when it makes sense not to follow it?) :)

i have a reasonable simple 'Post' model in my forum software (http://
sct.sphene.net/) which has a property 'is_hidden' which is usually 0
for normal posts. but for example for drafts i create new Post objects
with is_hidden = 1 - e.g. when a user uploads attachments which i
require to link to the Post before the user is done writing and
submitting his post.. (another example would be when an admin deletes
a Post - it is not removed from the database, but instead set to be
hidden)

so .. if is_hidden != 0 it should be like the Post instance doesn't
exist - and should never be returned - except in one or two places
(like when changing from draft to published state)

so what should i do? add a filter for is_hidden = 0 whereever i access
a list of posts through a related field, or is that a case where i can
ignore the advice in the documentation?

thanks,
herbert

p.s. the problem came up here: http://code.google.com/p/sct-project/issues/detail?id=186
- code for my not so simple Post object is here:
http://source.sphene.net/wsvn/sct/communitytools/trunk/sphenecoll/sphene/sphboard/models.py

Reply all
Reply to author
Forward
0 new messages