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: Piotr Malinski <riklaunim@…> 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 riklaunim@…, 18 years ago

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:

DoesNotExist at /admin/wiki/wikicategory/
WikiCategory matching query does not exist.
Request Method:
GET
  Request URL:
http://localhost:8080/admin/wiki/wikicategory/
  Exception Type:
DoesNotExist
  Exception Value:
WikiCategory matching query does not exist.
  Exception Location:
/usr/lib64/python2.4/site-packages/django/db/models/query.py in get, line 213
Template error
In template /usr/lib64/python2.4/site-packages/django/contrib/admin/templates/admin/change_list.html, error at line 17

Template variable that throw the exception: {% result_list cl %}

If I comment "objects = CurrentSiteManager()" in my model it list categories.

comment:2 by Lakin Wecker <lakin@…>, 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 Lakin Wecker <lakin@…>, 18 years ago

It seems that #2892 is a duplicate bug ... and there is a workaround on it.

comment:4 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: UnreviewedAccepted

comment:5 by James Bennett, 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 James Bennett, 17 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top