forms

Pass Instance With Predefined Data to Form (CBV)

August 21, 2022
forms

In case when you need to initialize form with already predefined details of the form instance, for example form that add comment to a post - you can predefine post_id in the form instance instead applying it in the save() method.

...

get_success_url() to Previous Page

August 21, 2022
forms

Easy way to redirect user on previous (original) page after form processing it is use HTTP_REFERER header, here an example how it’s may be implemented in the get_success_url() of the Django’s class based view.

...

Why Djnago Form Is Invalid How to Print Errors

August 17, 2022
forms

Working with complex views that process multiple forms you can stuck on situation when some of forms didn’t valitated but you have not see a reason for this, to debug this you can print forms errors from the view POST method.

...

Choices Yes/No for Boolean Field in Django

August 17, 2022
forms

Sometimes you need to represent boolean field of the Django model as dropdown list choices, like “Yes/No” instead default boolean field form widget - CheckboxInput. You can implement it like this.

...