In Django, how do I imitate the two-step method of adding users via admin for my own models?

I have a model where I would like to create a custom admin change_form that mimics the behavior of the Add User functionality in the Admin Django interface. That is, I want to perform a two-step action, when the user first enters only the device identifier, and then will be sent to a page where he can enter information about the device. Similar to how you first enter the username and password for the user, and then fill out other information on the next page. Any ideas?

+7
django django-admin
source share
1 answer

I finally managed to find how django does it. There is a response_add method overridden inside the correct ModelAdmin . Here is a link to it for the user model in the django source: django.contrib.auth.admin.py . It looks like this:

 def response_add(self, request, obj, post_url_continue='../%s/'): if '_addanother' not in request.POST and '_popup' not in request.POST: request.POST['_continue'] = 1 return super(UserAdmin, self).response_add(request, obj, post_url_continue) 

If you add this method to your ModelAdmin class, then it should work similarly.

This only covers the two-step save process in the admin panel, but other functions, such as adding additional fields to the form in the second step, can also be dug in the django source.

+7
source share

All Articles