2👍
✅
According to documentation‘s example, you can override save_model
like this:
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
def save_related(self, request, form, formsets, change):
if not form.cleaned_data['type']:
type, created = Type.objects.get_or_create(name="Teacher")
form.cleaned_data['type'] = [type]
form.save_m2m()
for formset in formsets:
self.save_formset(request, form, formset, change=change)
Source:stackexchange.com