<s> from functools import update_wrapper <EOL> from django . contrib import admin <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import models <EOL> from django . http import HttpResponseRedirect <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> @ python_2_unicode_compatible <EOL> class Action ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:50> , primary_key = True ) <EOL> description = models . CharField ( max_length = <NUM_LIT> ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> class ActionAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT:description>' ) <EOL> def remove_url ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return [ url for url in super ( ActionAdmin , self ) . get_urls ( ) if url . name != name ] <EOL> def get_urls ( self ) : <EOL> from django . conf . urls import patterns , url <EOL> def wrap ( view ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> return self . admin_site . admin_view ( view ) ( * args , ** kwargs ) <EOL> return update_wrapper ( wrapper , view ) <EOL> info = self . model . _meta . app_label , self . model . _meta . module_name <EOL> view_name = '<STR_LIT>' % info <EOL> return patterns ( '<STR_LIT>' , <EOL> url ( r'<STR_LIT>' , wrap ( self . add_view ) , name = view_name ) , <EOL> ) + self . remove_url ( view_name ) <EOL> class Person ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:20> ) <EOL> class PersonAdmin ( admin . ModelAdmin ) : <EOL> def response_post_save_add ( self , request , obj ) : <EOL> return HttpResponseRedirect ( <EOL> reverse ( '<STR_LIT>' , args = [ obj . pk ] ) ) <EOL> def response_post_save_change ( self , request , obj ) : <EOL> return HttpResponseRedirect ( <EOL> reverse ( '<STR_LIT>' , args = [ obj . pk ] ) ) <EOL> class Car ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:20> ) <EOL> class CarAdmin ( admin . ModelAdmin ) : <EOL> def response_add ( self , request , obj , post_url_continue = None ) : <EOL> return super ( CarAdmin , self ) . response_add ( <EOL> request , obj , post_url_continue = reverse ( '<STR_LIT>' , args = [ obj . pk ] ) ) <EOL> class CarDeprecated ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> name = models . CharField ( max_length = <NUM_LIT:20> ) <EOL> class CarDeprecatedAdmin ( admin . ModelAdmin ) : <EOL> """<STR_LIT>""" <EOL> def response_add ( self , request , obj , post_url_continue = None ) : <EOL> return super ( CarDeprecatedAdmin , self ) . response_add ( <EOL> request , obj , post_url_continue = '<STR_LIT>' ) <EOL> admin . site . register ( Action , ActionAdmin ) <EOL> admin . site . register ( Person , PersonAdmin ) <EOL> admin . site . register ( Car , CarAdmin ) <EOL> admin . site . register ( CarDeprecated , CarDeprecatedAdmin ) </s>
