Hello everyone, just getting acquainted with django and it became necessary to save the data in the database with the request, I saw examples of saving the form, but I do not need to use the form

def login(request): if request.method == 'POST': phone_sim = request.POST.get('number') userAditional.telefon = phone_sim.get('number') userAditional.telefon.save() 

As always, the answer is very simple, but unknowingly there are difficulties, with the query variable "number", in the database "telefon"

    1 answer 1

    Input data that will be saved to the database should always be checked. Therefore it is better to use the form. The model is not saved, because you call the save() method on the model attribute.

     userAditional.telefon = phone_sim.get('number') userAditional.save() 
    • Isn't it more difficult through a form? - maximus
    • @maximus Forms make it easier to validate data. Also, if you have several fields to save, it will be more convenient to create a model using the form. - Ivan Semochkin
    • I quickly set an example, do I do everything right? class userAditional(models.Model): telefon = models.IntField() class loginForm(forms.ModelForm): class Meta: model = userAditional fields = [ "telefon", ] - maximus
    • @maximus is impossible to read, there is nothing difficult in the forms. Read the documentation - Ivan Semochkin
    • OK, I will understand - maximus