#3987: ModelAdmin should allow for overriding of ForeignKey/ManyToMany options
----------------------------------------------------+-----------------------
   Reporter:  Baptiste <[EMAIL PROTECTED]>  |                Owner:  adrian     
    
     Status:  new                                   |            Component:  
Admin interface
    Version:  newforms-admin                        |           Resolution:     
            
   Keywords:                                        |                Stage:  
Accepted       
  Has_patch:  1                                     |           Needs_docs:  0  
            
Needs_tests:  0                                     |   Needs_better_patch:  0  
            
----------------------------------------------------+-----------------------
Changes (by Baptiste <[EMAIL PROTECTED]>):

  * needs_better_patch:  1 => 0

Comment:

 Okay, here is a new patch that I hope cleaner.
 
 It works almost like Adrian suggested it :
 {{{
 #!python
 # 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()
         return model.objects.filter(use_in_admin=True)
 }}}
 And also allows:
 {{{
 #!python
 class BookAdmin(ModelAdmin):
     def dynamic_author_choices(self, request, model):
         if request.user.is_superuser:
             return model.objects.all()
         return model.objects.filter(use_in_admin=True)
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3987#comment:8>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to