Search code examples
djangodjango-admin

Django admin _continue and _addanother not working


I have 3 buttons in django admin: save, save and add another, save and continue. They have their input names in html like _save, _addanother and _continue. All of these buttons do the same thing - save model and redirect to the main page (like when I click on the save button)

class StudyFormAdmin(admin.ModelAdmin):
    list_display = ['name']
    fields = ['name']

I found out that response_add method contains redirect functionality (https://github.com/django/django/blob/ef62a3a68c9d558486145a42c0d71ea9a76add9e/django/contrib/admin/options.py#L1316). Then I tried to check what in my request.POST. I add these lines to my model:

    def response_add(self, request, obj):
        print(request.POST)
        return super().response_add(request, obj)

Output: <QueryDict: {'csrfmiddlewaretoken': ['2IOoriUmt5IzfIKU7MY53hZ9dgupnM3sNU6ltcaKXXzwmDB73xekyXn55Pw197dF'], 'name': ['adfgdfg']}>

I have tried all these buttons for each model I have but response always the same


Solution

  • It looks like it was a Django4.1 bug, I migrated to Django4.2 and now everything is fine