06 – CUSTOMIZE DJANGO ADMIN INTERFACE – INVOICE MANAGEMENT SYSTEM

Spread the love

1. Create forms.py module in invoicemgmt app folder

2. In the forms.py module, import Django model form
from django import forms
In the same form.py module, import the Invoice model from models.py
from .models import Invoice

3. Create a model form in forms.py. Name the form InvoiceForm as shown below

class InvoiceForm(forms.ModelForm):
	class Meta:
		model = Invoice
		fields = ['name', 'phone_number', 'invoice_date',
				'line_one', 'line_one_quantity', 'line_one_unit_price', 'line_one_total_price',
				'line_two', 'line_two_quantity', 'line_two_unit_price', 'line_two_total_price',
				'line_three', 'line_three_quantity', 'line_three_unit_price', 'line_three_total_price',
				'line_four', 'line_four_quantity', 'line_four_unit_price', 'line_four_total_price',
				'line_five', 'line_five_quantity', 'line_five_unit_price', 'line_five_total_price', 
				'total', 'paid', 'invoice_type'
				]

4. In admin.py, import the InvoiceForm created in step 3 above
from .forms import InvoiceForm

Next, create a class, name it InvoiceAdmin, with list_display, form, list_filter, and search_field as shown below.

class InvoiceAdmin(admin.ModelAdmin):
   list_display = ['name', 'invoice_number', 'invoice_date']
   form = InvoiceForm
   list_filter = ['name']
   search_fields = ['name', 'invoice_number']

5. Modify your registration to apply the customization as below.

admin.site.register(Invoice, InvoiceAdmin)


Spread the love

About the author

arbadjie

Hi, I'm Abdourahman Badjie, an aspiring developer with obsession for anything coding and networking. This blog is dedicated to helping people learn to develop web applications using django framework.

View all posts

4 Comments

  • Hello Arbadjie,

    I wanted to Join through Patreon today, but I got this message “Renews automatically on November 1 at 12am Pacific Time”. I thought the monthly is 30 day from the day I subscribe. So, if I join today it will expire on 31st October 2021?
    please advice

    • Yes Patreon will collect your patronage (donation) the day you join then every end of the month. If you want to join you can wait till on the 1st or 2nd of the new month then join. Thanks in advance.

Leave a Reply to arbadjie Cancel reply

Your email address will not be published. Required fields are marked *