5.3. Admin Inlines
admin.StackedInline
admin.TabularInline
5.3.1. SetUp
>>> from django.contrib import admin
5.3.2. StackedInline
>>>
... class AddressInline(admin.StackedInline):
... model = CustomerAddress
... max_num = 10
... min_num = 0
... extra = 1
...
...
... @admin.register(Customer)
... class CustomerAdmin(model.ModelAdmin):
... inlines = [AddressInline]
5.3.3. TabularInline
>>>
... class AddressInline(admin.TabularInline):
... model = CustomerAddress
... max_num = 10
... min_num = 0
... extra = 1
...
...
... @admin.register(Customer)
... class CustomerAdmin(model.ModelAdmin):
... inlines = [AddressInline]
5.3.4. Use Case - 1
>>>
... from django.contrib import admin
...
...
... class AddressInline(admin.StackedInline):
... model = CustomerAddress
... extra = 1
...
...
... class PhoneInline(admin.TabularInline):
... model = Phone
... extra = 1
... radio_fields = {'type': admin.HORIZONTAL}
...
...
... @admin.register(Customer)
... class CustomerAdmin(model.ModelAdmin):
... inlines = [AddressInline, PhoneInline]