Ticket #3987: doc_diff.txt

File doc_diff.txt, 1.2 KB (added by ikse hefem, 16 years ago)

tentative feature documentation

Line 
1+++ django/docs/admin.txt Fri Aug 01 16:02:13 2008
2@@ -486,6 +486,35 @@
3 Performs a full-text match. This is like the default search method but uses
4 an index. Currently this is only available for MySQL.
5
6+``ModelAdmin`` methods
7+------------------------
8+
9+ModelAdmin subclasses can redefine specific methods in order to customize even more the admin site :
10+
11+``dynamic_XXX_choices``
12+~~~~~~~~~~~~~~~~~~~~~~~~~
13+
14+the ``dynamic_XXX_choices`` method, where XXX is a ForeignKey or ManyToMany field of your model, allows the admin site to filter the available choices for that field.
15+
16+An example usage of it is ::
17+
18+ # Model
19+
20+ class Book(models.Model):
21+ title = models.CharField(maxlength=100)
22+ author = models.ForeignKey(Author)
23+
24+ # Admin
25+
26+ class BookAdmin(ModelAdmin):
27+ def dynamic_author_choices(self, request, model):
28+ # Default implementation:
29+ # return book.author_set.all()
30+ if request.user.is_superuser:
31+ return model.objects.all()
32+ return model.objects.filter(use_in_admin=True)
33+
34+
35 ``ModelAdmin`` media definitions
36 --------------------------------
37
Back to Top