Я пытаюсь изменить логи c для сохранения данных в Django admin. Я переопределяю save_model
, но получаю ошибку "<User: test_user>" needs to have a value for field "id" before this many-to-many relationship can be used.
class UserAdminForm(forms.ModelForm):
middle_name = forms.CharField(label='Middle name')
class Meta:
labels = {
'last_name': 'Last name',
'first_name': 'First name',
'password': 'Password',
}
class UserAdmin(admin.ModelAdmin):
form = UserAdminForm
fields = ['username', 'password', 'last_name', 'first_name', 'middle_name', 'groups']
list_display = ['username', 'last_name', 'first_name', ]
def save_model(self, request, obj, form, change):
print(form)