views:

101

answers:

2

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)

Edit

No, my own answer didn't work. I misunderstood the redirect app

Edit 2

Daniel's answer did half the job: Redirect after changing the articles and categories.

Edit 3

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?

A: 

I think, i just found it: docs.djangoproject.com/en/dev/ref/contrib/redirects/

vikingosegundo
+3  A: 

In your admin subclass, override the response_change and/or the response_add methods. These are called after the admin form is saved ,for existing and new instances respectively, and are responsible for returning the HttpResponseRedirect that currently takes you to the change_list page.

Take a look at the original code in django.contrib.admin.options to 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_list page, in which case you can use the response_action method; 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 the change_form.html template for the app, and remove the deletion link, so that the only way to delete is via the changelist. Not ideal by any means.

Daniel Roseman
Thanks! That did it
vikingosegundo
or at least half answered: How to redirect after delete?
vikingosegundo
See my edited response above.
Daniel Roseman