Answer the question
In order to leave comments, you need to log in
How does the save method of a ModelForm work?
I am new to Django learning forms. I have overridden the clean method which checks the data, changes some fields, and returns it. I want to understand how do I use save on a form in a tie, does it save the cleared data to the model or not, and if not then how to save the cleared data to the model. Now I'm using a regular Form and manually saving the data to the model, and this is not very convenient. I know that everything is written about this in the documentation, but it is not always clear there. Thanks in advance for your understanding.
Answer the question
In order to leave comments, you need to log in
If you are talking about the *form class object).save() command, then it saves a record in the database with the fields that were registered in fields in the form class, provided that the data validation was successful, otherwise an error will occur. In the fields, it saves the cleaned data, which, by the way, you can access through the *object of the form class*.cleaned_data. This is a dictionary where all the data passed through the clean method will be. And so, dude, it’s not necessary to check the documentation, use tutorials, watch video tutorials, it’s basically inefficient for a beginner to deal with documentation, it was created for those who have already worked with other frameworks, and not for completely inexperienced ones. And the things that are in the documentation are almost useless to ask on the forums, they don’t like them here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question