1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #8001 -- Made redirections after add/edit in admin customizable.

Also fixes #18310.
This commit is contained in:
Ramiro Morales
2012-10-18 20:58:52 -03:00
parent db598dd8a0
commit 0b908b92a2
4 changed files with 190 additions and 48 deletions

View File

@@ -50,3 +50,40 @@ class ActionAdmin(admin.ModelAdmin):
admin.site.register(Action, ActionAdmin)
class Person(models.Model):
nick = models.CharField(max_length=20)
class PersonAdmin(admin.ModelAdmin):
"""A custom ModelAdmin that customizes the deprecated post_url_continue
argument to response_add()"""
def response_add(self, request, obj, post_url_continue='../%s/continue/',
continue_url=None, add_url=None, hasperm_url=None,
noperm_url=None):
return super(PersonAdmin, self).response_add(request, obj,
post_url_continue,
continue_url, add_url,
hasperm_url, noperm_url)
admin.site.register(Person, PersonAdmin)
class City(models.Model):
name = models.CharField(max_length=20)
class CityAdmin(admin.ModelAdmin):
"""A custom ModelAdmin that redirects to the changelist when the user
presses the 'Save and add another' button when adding a model instance."""
def response_add(self, request, obj,
add_another_url='admin:admin_custom_urls_city_changelist',
**kwargs):
return super(CityAdmin, self).response_add(request, obj,
add_another_url=add_another_url,
**kwargs)
admin.site.register(City, CityAdmin)