python - How can I update only certain fields in a Django model form? -


I have a model form that I use to update a model.

TurtleForm (models.Model): name = models.CharField (MAX_LENGTH = 50, empty = false) Description = models.TextField (empty = true) class TurtleForm (forms.ModelForm): Class meta model = turtle

Sometimes I do not need to update the entire model, but only one field has to be updated. So when I post only information is available for details when I never save that model, because it thinks that the name is being blanked out, while my intention is that the name does not change and just use it from the model To be done.

  turtle_form = TurtleForm (request .post, example = object) if turtle_form.is_valid (): turtle_form.save ()  

is there any way to do this The way? Thanks!

Use only the specified field:

  class first model forms ModelForm): Square Meta: Model = TheModel fields = ('title', def deftitle) (see itself ....  

View Different model models for a model in different scenes, when you want different features, so creating another form for a model using the same behavior (such as clean_ methods etc.) IG: Class II ModelFormFormodelform: Class Meta: Model = TheModel fields = ('title', 'description')


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -