Django

Code

Ticket #2609 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

CurrentSiteManager needs models.Manager() for admin to function.

Reported by: dean@nevins.org Assigned to: adrian
Milestone: Component: Admin interface
Version: SVN Keywords: CurrentSiteManager
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When using the CurrentSiteManager? in your objects you must include the models.Manager() for the admin interface to work. In the docs on the "sites" framework under The CurrentSiteManager? the Photo object example is given. In this example the CurrentSiteManager? and the models.Manager() are both explicitly defined so this works. If you do not define the models.Manager() when you use the CurrentSiteManager? the admin interface will fail with a ChangeManipulator? error (contrib/admin/views/main.py line 317). Nowhere in the docs does it state that you must define both. I think that this is an error since the models.Manager() should still be automatically created even if you use a CurrentSiteManager?. A workaround is to define both as shown in the example.

Attachments

Change History

08/28/06 02:14:36 changed by Dean Nevins

Not only do you need to define the models.Manager but you must use the same order as in the example or even that won't work.

For example, this works:

class Rabbit(models.Model):
    title = models.CharField(maxlength=50,core=True,blank=False)
    site = models.ForeignKey(Site,core=True)
    objects = models.Manager()
    on_site = CurrentSiteManager()

This doesn't:

class Rabbit(models.Model):
    title = models.CharField(maxlength=50,core=True,blank=False)
    site = models.ForeignKey(Site,core=True)
    on_site = CurrentSiteManager()
    objects = models.Manager()

08/28/06 09:52:57 changed by ubernostrum

This isn't an error, but the docs could do a better job of pointing at the documentation for custom managers, which does explain that the first manager defined for a model will be the default one, and that defining one or more custom managers will cause the "automatic" objects manager not to be created for you, so that you'll have to create it manually if you want to keep it.

08/30/06 23:08:25 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [3686]) Fixed #2609 -- Improved docs/sites.txt CurrentSiteManager? to explain gotcha with models.Manager

10/18/06 23:21:30 changed by Lakin Wecker <lakin@evolvs.com>

  • status changed from closed to reopened.
  • resolution deleted.

Actually, the documentation is somewhat wrong ...

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.

10/19/06 09:22:31 changed by Lakin Wecker <lakin@evolvs.com>

  • status changed from reopened to closed.
  • resolution set to fixed.

Sorry, my comments are a duplicate of #2892 #2644. Changing back to fixed ...


Add/Change #2609 (CurrentSiteManager needs models.Manager() for admin to function.)




Change Properties
Action