Opened 18 years ago
Closed 17 years ago
#2644 closed defect (wontfix)
Object listing in Admin Panel lists all objects even when "objects" manager is changed
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | 0.95 |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For example a model class:
class Category(models.Model): objects = CurrentSiteManager() site = models.ForeignKey(Site, blank=True, default=settings.SITE_ID) cat_name = models.CharField(maxlength=255, verbose_name="Category Name") # name of the category cat_order = models.PositiveSmallIntegerField(default=0, verbose_name="Order") # order of categories on the forum-categories list class Meta: verbose_name = "Category" verbose_name_plural = "Categories" class Admin: list_display = ('cat_name', 'cat_order', 'site') fields = ( (None, { 'fields': ('cat_name', 'cat_order') }),) def __str__(self): return self.cat_name
It uses Sites to add/edit/show objects for current site by SITE_ID. The problem is that in Admin Panel list of objects will show all objects, not only from current site, while editing will work only for objects assigned to current site (other will get Page not found (404) when trying to edit them). Admin Panel should use THECLASS.objects.all() in this case...
Change History (6)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
I've tracked it down a bit more, this is due to:
The administration doesn't use the appropriate object all of the time ... check out line 216 of db/models/options.py
self.manager = manager or Manager()
This manager gets used in a number of places, more importantly it gets used by the ChangeList? class for the admin interface, so the change list shows instances of the model for all sites, regardless of whether your CurrentSiteManager? is first or not ...
I hope you don't mind that I'm re-opening the ticket. At the very least, the documentation should be updated.
comment:3 by , 18 years ago
It seems that #2892 is a duplicate bug ... and there is a workaround on it.
comment:4 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 18 years ago
The functionality in newforms-admin will fix this -- you'll be able to manually specify how to retrieve objects for the changelist, and the default should be the model's default manager.
comment:6 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Since no-one's raised any further issues in seven months of this ticket idling, and since this issue is not relevant on newforms-admin, I'm marking wontfix.
I've added some categories to site ID 1 and site ID 2 and when I want to see a list of categories I get:
Template variable that throw the exception: {% result_list cl %}
If I comment "objects = CurrentSiteManager()" in my model it list categories.