#3987: ModelAdmin should allow for overriding of ForeignKey/ManyToMany options
-----------------------------------------------------------+----------------
          Reporter:  Baptiste <[EMAIL PROTECTED]>  |         Owner:  nobody     
   
            Status:  reopened                              |     Milestone:     
           
         Component:  django.contrib.admin                  |       Version:  
newforms-admin
        Resolution:                                        |      Keywords:  
nfa-someday   
             Stage:  Design decision needed                |     Has_patch:  1  
           
        Needs_docs:  0                                     |   Needs_tests:  1  
           
Needs_better_patch:  1                                     |  
-----------------------------------------------------------+----------------
Changes (by mwdiers):

  * needs_better_patch:  0 => 1
  * needs_tests:  0 => 1
  * stage:  Someday/Maybe => Design decision needed

Comment:

 Sorry. Had some superfluous code in that example. Updated version for
 reference:

 {{{
 #!python
 class SiteAdmin(ModelAdmin):
     def __call__(self, request, url):
         #Add in the request object, so that it may be referenced
         #later in the formfield_for_dbfield function.
         self.request = request
         return super(SiteAdmin, self).__call__(request, url)

     def formfield_for_dbfield(self, db_field, **kwargs):
         field = super(SiteAdmin, self).formfield_for_dbfield(db_field,
 **kwargs) # Get the default field
         if db_field.name == 'home_page':
             #Add the null object
             my_choices = [('', '---------')]
             #Grab the current site id from the URL.
 
my_choices.extend(Page.objects.filter(site=self.request.META['PATH_INFO'].split('/')[-2]).values_list('id','name'))
             print my_choices
             field.choices = my_choices
         return field
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3987#comment:32>
Django <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