'Is it possible to allow to create objects from the list_display view of the django admin site?

I have a model with fields name, roll_no, birth_date I am using the django admin's list display and list editable to have these fields displayed and edited in a list format in a single page. However, to add a new entry I have to go to the create_form page. Is it possible to simply add new objects from the list_display page itself?



Solution 1:[1]

Unfortunately this feature is not available out-of-the box in the Django admin like the ModelAdmin.list_editable feature.

I'm curious to see if there are other shortcuts, but at the moment the only way I see is to customize the formset like descibed in the official Docs:

from django import forms

class MyForm(forms.ModelForm):
    # customize your 'extra' forms here

class MyModelAdmin(admin.ModelAdmin):
    def get_changelist_form(self, request, **kwargs):
        return MyForm

And finally manually extend the changelist form template of the admin. To override a Django admin template, please follow the intructions in the Official Docs here. The template to be customized is the following folder:

.../django/contrib/admin/templates/admin/change_list.html

and you probably need to override the {% block result_list %} in that file.

NB: the customization of an admin template can be very tricky. Consider to use a CMS (like DjangoCMS) if you need to extend the user experience. The idea behind the Django admin is to make your life easier with an out-of-the-box interface for CRUDs on your DB. IMHO try to avoid complex customizations of the Django Admin if not strictly needed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1