+++ django/docs/admin.txt Fri Aug 01 16:02:13 2008 @@ -486,6 +486,35 @@ Performs a full-text match. This is like the default search method but uses an index. Currently this is only available for MySQL. +``ModelAdmin`` methods +------------------------ + +ModelAdmin subclasses can redefine specific methods in order to customize even more the admin site : + +``dynamic_XXX_choices`` +~~~~~~~~~~~~~~~~~~~~~~~~~ + +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. + +An example usage of it is :: + + # Model + + class Book(models.Model): + title = models.CharField(maxlength=100) + author = models.ForeignKey(Author) + + # Admin + + class BookAdmin(ModelAdmin): + def dynamic_author_choices(self, request, model): + # Default implementation: + # return book.author_set.all() + if request.user.is_superuser: + return model.objects.all() + return model.objects.filter(use_in_admin=True) + + ``ModelAdmin`` media definitions --------------------------------