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 3 years, 10 months ago
  2. FieldsetForm by Ciantic 6 years, 1 month ago
  3. ActiveManager: filter objects depending on publication and/or expiration dates by haplo 4 years, 10 months ago
  4. Django enumeration for model field choices by martinthenext 1 year, 1 month ago
  5. Fetching top items by ubernostrum 6 years, 2 months 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?)