Relative Content

Tag Archive for djangodjango-forms

Define commonly used form fields in Django

I have an app where there are some search forms on different pages. One commonly used form field would be ‘show x items’, where x can be 10, 20 or 50. I would also like a field ‘Sort by’ with some standard values. I have used Django model mixins earlier, e.g. CreateTimestampMixin, which standardizes the column name ‘create_ts’ in my models, and I want to have something similar in my forms now. Note: These are just forms, not model forms. Is there a way that I can do it? Or must I only define a new field type that derives from forms.ChoiceField, plugin my choice values, and then in each form define this field?

how to customize all-auth errors for mismatch passwords to othere languge?

class PasswordVerificationMixin(object):
def clean(self):
cleaned_data = super(PasswordVerificationMixin, self).clean()
password1 = cleaned_data.get(“password1”)
password2 = cleaned_data.get(“password2”)
if (password1 and password2) and password1 != password2:
self.add_error(“password2”, _(“You must type the same password each time.”))
return cleaned_data
I want to override this class and make the error message to ‘this a test’
i am stuck i tried overriding it but nothing any help?

How to pass a Django form response through another template

I am creating a site for users to record their chicken’s weights and I am trying to design a confirmation form for if a user tries to submit another weight for the same chicken on the same day. In other words, if a record already exists for that date, how to ask the user if it should be overwritten without the user re-entering the weight.
This is all I have so far: