Update View not updating table when Rendering fields manually

223 views
Skip to first unread message

Sumit Kumar

unread,
Jan 3, 2018, 7:03:36 AM1/3/18
to django...@googlegroups.com

When I am using simply this

                <form action="" method="post" enctype="multipart/form-data">
                    {% block content %}
                       {% csrf_token %}
                       {{ form }}
                       <input type="submit" value="Update" />
                    {% endblock content %}
                </form>

It is updating my JobFinal Table I can see POST /JobSchd/jobform_final/3/update/ HTTP/1.1" 302 0 But when changing {{ form }} to {{ form.job_name }} It doesn't update the table and doesn't redirect to the reverse url.And I can see POST /JobSchd/jobform_final/3/update/ HTTP/1.1" 200 4492

Here is my snippet of related View.py

class JobFinalUpdate(UpdateView):
    model = JobFinal
    form_class = JobFormFinal
    template_name_suffix = '_update_form'


    def get_success_url(self):
        return reverse('JobSchd:user_details',kwargs={'pk': self.request.user.id})

Here is my form.py class JobFormFinal(forms.ModelForm):

class Meta:
    model=JobFinal
    exclude=['user']
Thank You!
Kind Regards,
Sumit Kumar| +1-480-740-7728

Please consider the environment before printing.


Matemática A3K

unread,
Jan 3, 2018, 2:45:42 PM1/3/18
to django...@googlegroups.com
On Wed, Jan 3, 2018 at 1:53 AM, Sumit Kumar <postme...@gmail.com> wrote:

When I am using simply this

                <form action="" method="post" enctype="multipart/form-data">
                    {% block content %}
                       {% csrf_token %}
                       {{ form }}
                       <input type="submit" value="Update" />
                    {% endblock content %}
                </form>

It is updating my JobFinal Table I can see POST /JobSchd/jobform_final/3/update/ HTTP/1.1" 302 0 But when changing {{ form }} to {{ form.job_name }} It doesn't update the table and doesn't redirect to the reverse url.And I can see POST /JobSchd/jobform_final/3/update/ HTTP/1.1" 200 4492

Because {{ form }} makes the template engine print all the fields (and error handling code) of the form, while {{ form.job_name }} will do it for just the "job_name" field. If there are more fields required for the form being valid, in the view it will never be succesful and the get_success_url won't be executed. You won't see any error in the template because that is printed by {{ form }} - which is not there
 

Here is my snippet of related View.py

class JobFinalUpdate(UpdateView):
    model = JobFinal
    form_class = JobFormFinal
    template_name_suffix = '_update_form'


    def get_success_url(self):
        return reverse('JobSchd:user_details',kwargs={'pk': self.request.user.id})

Here is my form.py class JobFormFinal(forms.ModelForm):

class Meta:
    model=JobFinal
    exclude=['user']
Thank You!
Kind Regards,
Sumit Kumar| +1-480-740-7728

Please consider the environment before printing.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOvNbK5MPctf16RfaZzcfc%3Dt4USd%2B3Ey0H0mm7hT%3DGeh_zbyug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages