Code

Opened 8 years ago

Closed 7 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: UI/UX:

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...

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by riklaunim@…

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 Changed 8 years ago by Lakin Wecker <lakin@…>

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 Changed 8 years ago by Lakin Wecker <lakin@…>

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

comment:4 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 7 years ago by ubernostrum

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 Changed 7 years ago by ubernostrum

  • Resolution set to wontfix
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.