django model form modelForm preservation method 200 318

Here Insert Picture Description

Form Validation success can be directly saved

Here Insert Picture Description

Case exercises

Problems

When performing form validation code is to be entered twice

Paul is saved to the database is stored only once

What should I do?

The original model

Which can be added to the model-based validation rules if necessary

Here Insert Picture Description

Defined form model class

Here Insert Picture Description

Ruled out password

Two custom form model class field

Verify that both passwords are the same in the form model class

Method override the parent class clean

Here Insert Picture Description

View Data Processing

Here Insert Picture Description

数据行对象 = 对象.save(commit=False)


Without commit the False

Form over the data will be stored directly to the table

Since the model form classes omit the password

So even in this 数据行对象which adds to the value of the password

Can be saved by a save method after bin

Published 298 original articles · won praise 1 · views 4060

Guess you like

Origin blog.csdn.net/whalecode/article/details/104940498