django-forms

Why does my excluded field still appear in this Django form?

蓝咒 提交于 2021-02-07 05:21:28
问题 I'm using exclude in my form's Meta class to exclude a field from my form that I want to fill in programatically, but it's still showing up in the form. Here are some excerpts from the code: # Model class Info(models.Model): completed_by = models.ForeignKey(User, related_name='+') # Form class InfoForm(forms.ModelForm): class Meta: model = Info exclude = ('created_by',) #ETA: added comma to make this a tuple widgets = { 'some_other_field': forms.HiddenInput(), 'some_other_field2': forms

Why does my excluded field still appear in this Django form?

纵然是瞬间 提交于 2021-02-07 05:21:11
问题 I'm using exclude in my form's Meta class to exclude a field from my form that I want to fill in programatically, but it's still showing up in the form. Here are some excerpts from the code: # Model class Info(models.Model): completed_by = models.ForeignKey(User, related_name='+') # Form class InfoForm(forms.ModelForm): class Meta: model = Info exclude = ('created_by',) #ETA: added comma to make this a tuple widgets = { 'some_other_field': forms.HiddenInput(), 'some_other_field2': forms

Custom Label in Django Formset

与世无争的帅哥 提交于 2021-02-06 11:41:04
问题 How do I add custom labels to my formset? <form method="post" action=""> {{ formset.management_form }} {% for form in formset %} {% for field in form %} {{ field.label_tag }}: {{ field }} {% endfor %} {% endfor %} </form> My model is: class Sing(models.Model): song = models.CharField(max_length = 50) band = models.CharField(max_length = 50) Now in the template instead of the field label being 'song' , how do i set it so that it shows up as 'What song are you going to sing?' ? 回答1: You can use

Display form errors with django and ajax

别等时光非礼了梦想. 提交于 2021-02-06 09:08:34
问题 I have a contact form through which users would be able to contact me. I am using django with ajax, and it works fine if there's no error. I would like to show the errors if there's any like it displays above the input fields and not just the errors, but both the input and the errors. It does however differentiate between the success and error result, as the ajax request was successful. But I need to display the actual form errors. How do I that? Your help will be very much appreciated. Thank

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

送分小仙女□ 提交于 2021-02-05 08:12:41
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

半城伤御伤魂 提交于 2021-02-05 08:11:34
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

Django Form validation including the use of session data

Deadly 提交于 2021-02-01 20:49:14
问题 The use case I am try to address is a requirement for a user to have downloaded a file before being permitted to proceed to the next stage in a form process. In order to achieve this, I have a Django Form to capture the user's general information which POSTS to Django view 'A'. The Form is displayed using a template which also includes an iFrame with a simple embedded button which links to the URL of Django view 'B'. View 'B' simply sets a session variable to indicate that the download has

Django Form validation including the use of session data

冷暖自知 提交于 2021-02-01 20:47:38
问题 The use case I am try to address is a requirement for a user to have downloaded a file before being permitted to proceed to the next stage in a form process. In order to achieve this, I have a Django Form to capture the user's general information which POSTS to Django view 'A'. The Form is displayed using a template which also includes an iFrame with a simple embedded button which links to the URL of Django view 'B'. View 'B' simply sets a session variable to indicate that the download has

Django Form validation including the use of session data

倾然丶 夕夏残阳落幕 提交于 2021-02-01 20:47:27
问题 The use case I am try to address is a requirement for a user to have downloaded a file before being permitted to proceed to the next stage in a form process. In order to achieve this, I have a Django Form to capture the user's general information which POSTS to Django view 'A'. The Form is displayed using a template which also includes an iFrame with a simple embedded button which links to the URL of Django view 'B'. View 'B' simply sets a session variable to indicate that the download has

Django Form validation including the use of session data

半城伤御伤魂 提交于 2021-02-01 20:47:13
问题 The use case I am try to address is a requirement for a user to have downloaded a file before being permitted to proceed to the next stage in a form process. In order to achieve this, I have a Django Form to capture the user's general information which POSTS to Django view 'A'. The Form is displayed using a template which also includes an iFrame with a simple embedded button which links to the URL of Django view 'B'. View 'B' simply sets a session variable to indicate that the download has