Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to add field to django forms createview

class MyModelCreateView(CreateView):
    model= My_model
    form_class = MyModelForm
    template_name = "application/mymodel.html"

    def form_valid(self, form):
    # comment: this fn will return the data from the HTML form 
    # and add to it the missing attrs of the model then save it
        form.instance.attr_1='string I want to save'
        #to save a clean string pass it between '' not ""
        form.instance.attr_2='a'
        return super().form_valid(form)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #field #django #forms #createview
ADD COMMENT
Topic
Name
6+9 =