Override a form in Django admin

后端 未结 2 1402
心在旅途
心在旅途 2020-12-02 13:23

In Django admin I want to override and implement my own form for a model (e.g. Invoice model).

I want the invoice form to have auto-fill fields for customer name, pr

2条回答
  •  不思量自难忘°
    2020-12-02 14:03

    You can override forms for django's built-in admin by setting form attribute of ModelAdmin to your own form class. See:

    1. https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form
    2. https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin

    It's also possible to override form template - have a look at https://docs.djangoproject.com/en/dev/ref/contrib/admin/#custom-template-options

    If you're looking specifically for autocomplete I can recommend https://github.com/crucialfelix/django-ajax-selects

提交回复
热议问题