Specify a manager for the Admin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Article(models.Model):
	site = models.ForeignKey(Site)
	title = models.CharField(max_length=100)
	body = models.TextField()
	pub_date = models.DateTimeField()
	
	class Admin:
		#  In this example, the Admin's object list will show *only* Articles
		#  which are related to the current Site.
		#  However, you could specify any Manager you like:
		#  manager = MyCustomManager()
		from django.contrib.sites.managers import CurrentSiteManager
		manager = CurrentSiteManager()
	

More like this

  1. User manager by diverman 2 years, 10 months ago
  2. Limit ForeignKey filter values to those that have a relationship with current model by overclocked 1 year, 6 months ago
  3. SSL Middleware for Webfaction by parlar 5 years ago
  4. showing environment variables in the django admin by tonemcd 2 years, 4 months ago
  5. Allow filtering and ordering by counts of related query results by exogen 5 years, 1 month ago

Comments

peterbe (on September 14, 2009):

This does not work in Django 1.1 where you don't use the Admin class but where you have ModelAdmin class registered separately.

#

(Forgotten your password?)