#26397: Use custom managers on Foreign Key
----------------------------------------------+--------------------
Reporter: vladlep | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Hi,
My case is similar as the one described in ticket #3871 but that one was
solved in a way that does not cover my problem:
I have a Category model that has a boolean flag is_active. Two managers
are on this model, the default one excludes categories that are inactive
(is_active=False) while a second managers including_inactive retrieves all
categories.
I have also an Article that has a foreign key to a Category model. On all
the other models I would like to see only the active categories but on the
Article FK, i would like to be able to choose from inactive ones also. To
do, the nicest way would be to just have an option:
{{{
class Article(models.Model):
models.ForeignKey(Category, manager=Category.including_inactive)
}}}
Ticket #3871 created this solution but that is not really the same:
https://docs.djangoproject.com/en/1.8/topics/db/queries/#using-custom-
reverse-manager
I also find this solution but that would change it on all the related
mangers, while I want it only on one:
http://stackoverflow.com/questions/7489635/how-to-use-custom-manager-with-
related-objects
To hack around, it I found this solution but would be nice if this would
be included in django if it you consider it would be useful:
http://www.hoboes.com/Mimsy/hacks/custom-managers-django-foreignkeys/
Best,
Vlad
--
Ticket URL: <https://code.djangoproject.com/ticket/26397>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.912d861958a4568636f1a868f272a962%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.