I have an app called CMS with Category and Article. Quite simple.
I overwrite app_index.html to enable ajax-based drag-n-drop ordering and to move articles from one category to another.
Now I would like to redirect after saving/deleting an article or a category to cms’ app_index.html instead of the model’s change_list.html. How can this be done?
Thanks
class Category(models.Model):
order = models.IntegerField()
title = models.CharField(max_length=100)
text = models.TextField()
class Article(models.Model):
published = models.BooleanField(default=None)
images = generic.GenericRelation(Photo)
category = models.ForeignKey(Category)
title = models.CharField(max_length=100)
text = models.TextField()
order = models.IntegerField(blank = True, null = True)
Daniel’s answer did half the job: Redirect after changing the articles and categories.
A not very elegant solution: Redirection in urls.py
def redirect_cms(response):
return HttpResponseRedirect('/admin/cms/')
urlpatterns += patterns('',
(r'^admin/cms/article/$',redirect_cms),
any other idea?
In your
adminsubclass, override theresponse_changeand/or theresponse_addmethods. These are called after the admin form is saved ,for existing and new instances respectively, and are responsible for returning theHttpResponseRedirectthat currently takes you to the change_list page.Take a look at the original code in
django.contrib.admin.optionsto see what you need to do.Edit: There are two ways a deletion can take place: as a result of an action on the
change_listpage, in which case you can use theresponse_actionmethod; or as a result of a deletion on the change form, in which case unfortunately there is no equivalent method. One way of dealing with this might be to override thechange_form.htmltemplate for the app, and remove the deletion link, so that the only way to delete is via the changelist. Not ideal by any means.