Code

Changes between Version 56 and Version 57 of NewformsHOWTO


Ignore:
Timestamp:
04/28/11 05:24:23 (3 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewformsHOWTO

    v56 v57  
    646646== Q: How can I pass extra context variables into my index page? == 
    647647 
    648 You can't. At least not in the same way as above. 
    649  
    650 There are two ways you can do this at present, the messy way or the 'proper' way. 
    651  
    652 The messy way is as follows. 
    653 Create a file called extras.py in your project's root directory (where urls.py lives). 
    654 In it create a copy of the index method from django.contrib.admin.sites (from the class ``AdminSite``). 
    655 Modify the method to add in your extra context variables. 
    656  
    657 In your urls.py import your new method and the 'new' module. 
    658 {{{ 
    659 #!python 
    660 from django.contrib import admin 
    661 from your_project.extras import new_index_method 
    662 import types 
    663 }}} 
    664  
    665 Now you'll need to replace the existing index method with your new one 
    666 {{{ 
    667 #!python 
    668 admin.site.index = types.MethodType(new_index_method) 
    669 }}} 
    670  
    671 this isn't that pretty but it works. 
    672  
    673 The 'proper' way will be to create your own ``AdminSite`` instance and register your models to it. The problem with this method is that you will also need to register all of the models from the auth app if you want to manage your users. 
    674  
    675 {{{ 
    676 #!python 
    677 from your_project.extras import my_admin_site_instance 
    678 ... 
    679 urlpatterns = patterns('', 
    680     # Override index page to add in fortune output 
    681     (SITE_BASE+r'/(.*)', my_admin_site_instance.root), 
    682 ... 
    683 }}} 
     648You couldn't in the past, but can now: 
     649 
     650In your urls,  
     651 
     652{{{ 
     653#!python 
     654(r'^admin/', admin.site.index, {'extra_context': {'foo':bar}}), 
     655}}} 
     656 
     657Then, you just need to update your admin/index.html template to make use of the new context. 
     658 
    684659 
    685660== Q: How can I change where I get sent after saving a new entry to the database? ==