Add a Save and view next button to your admin change form.
Put the code at link in a file called myapp/templates/admin/myapp/change_form.html
Note: Requires Django 1.2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | """admin.py"""
from django.contrib import admin
from django.http import HttpResponseRedirect
from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy as _
from myapp.models import MyModel
class MyAdmin(admin.ModelAdmin):
def response_change(self, request, obj):
"""
Determines the HttpResponse for the change_view stage.
"""
if request.POST.has_key("_viewnext"):
msg = (_('The %(name)s "%(obj)s" was changed successfully.') %
{'name': force_unicode(obj._meta.verbose_name),
'obj': force_unicode(obj)})
next = obj.__class__.objects.filter(id__gt=obj.id).order_by('id')[:1]
if next:
self.message_user(request, msg)
return HttpResponseRedirect("../%s/" % next[0].pk)
return super(MyAdmin, self).response_change(request, obj)
admin.site.register(MyModel, MyAdmin)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
The problem is that this does not test where the "next" item is in terms of the existing ordering.
#
Please login first before commenting.