Questions tagged [cleaned-data]
38 questions
55
votes
7 answers
How to access data when form.is_valid() is false
When I have a valid Django form, I can access the data with form.cleaned_data. But how do I get at the data a user entered when the form is not valid i.e., form.is_valid is false.
I'm trying to access forms within a form set, so form.data seems to…

Greg
- 45,306
- 89
- 231
- 297
13
votes
2 answers
What is the use of cleaned_data in Django
Django says if form.is_valid() is True. form.cleaned_data is where all validated fields are stored. But I am confused about using the cleaned_data function.
form.cleaned_data['f1'] -- cleaned data
request.POST.get('f1') -- un-validated data
I have…

Aseem
- 5,848
- 7
- 45
- 69
7
votes
1 answer
Django - ChoiceField cleaned_data gets String instead of Integer
I have a form field called 'units' like this:
units = forms.ChoiceField(choices=[(x, x) for x in range(1, 11)], help_text = 'Units: ')
When I do form.cleaned_data['units'] I get a String instead of an Integer.
How can I change the field to get…

Jorge Cámara
- 343
- 2
- 9
7
votes
1 answer
access parent form's cleaned_data from inline form clean()
I have a main form that has an inline-form. Is it possible to access the main form's cleaned_data from the inline-form's clean function?
Here is why I am asking.
The main form has a field to define if a property is for-sale or to lease. The inline…

bmeyer71
- 362
- 3
- 10
- 23
6
votes
3 answers
create() takes 1 positional argument but 2 were given? Django
I was confused to why when I run this code it returns an error
create() takes 1 positional argument but 2 were given
if request.method == "POST":
my_form = RawProductCreateForm(request.POST)
if my_form.is_valid():
…

Ayyoub
- 4,581
- 2
- 19
- 32
5
votes
4 answers
Problems raising a ValidationError on a Django Form
I'm trying to validate that a submitted URL doesn't already exist in the database.
The relevant parts of the Form class look like this:
from django.contrib.sites.models import Site
class SignUpForm(forms.Form):
# ... Other fields ...
url =…

saturdayplace
- 8,370
- 8
- 35
- 39
5
votes
4 answers
Django MultipleChoiceField does not preserve order of selected values
I have a Django ModelForm which exposes a multiple choice field corresponding to a many-to-many relation through a model which holds order of selection (a list of documents) as an extra attribute. At the front-end, the field is displayed as two…

onurmatik
- 5,105
- 7
- 42
- 67
4
votes
1 answer
Django: Save cleaned_data in a session effectively
In one of my forms, I am processing the form data and save it in a session variable.
So when I run
if locationForm.is_valid():
I execute
request.session['streetNumber'] = locationForm.cleaned_data['streetNumber']
request.session['postalCode'] =…

neurix
- 4,126
- 6
- 46
- 71
2
votes
2 answers
Key error in Django on form with prefix
I am using two forms on one page (I have my reasons). They are not model forms. I am trying to validate them by using prefix. I found it here: Proper way to handle multiple forms on one page in Django
But when I try to get cleaned_data, i get key…

Kroitus
- 61
- 1
- 6
2
votes
1 answer
form.cleaned_data is while form handling
It's a really simple form but I don't know where's got wrong. When I check the debug mode of django site, I found that the clean_data of new field is missing, as the picture of following:
class PasswordEditForm(forms.Form):
old =…

JianWei
- 121
- 2
- 6
2
votes
1 answer
Form's cleaned_data is empty but formset's cleaned_data isnt?
I am trying to use the String values from a CharField in each form of a formset, however for some reason the cleaned_data for each form always appeares empty while the formset's cleaned data is not. Here is the code from my views.py:
TagsFormSet…

James
- 197
- 2
- 13
1
vote
3 answers
What's the difference between Cleaned data and is valid in django
What is the difference between cleaned_data and is_valid functions in django?, I just came across forms and immediately i got stuck there
can anyone play with some simple examples. I've read many documentation but i cant able to differentiate it.

janezio
- 53
- 9
1
vote
1 answer
Django Form with validation state for unique
I try to add a validation state like "this already exist." (like registration form, see picture) just under my form input.
But when I submit my form i'v this error 'UNIQUE constraint failed'
this is my code
model
class Company(models.Model):
…

tomferrari
- 53
- 4
1
vote
2 answers
how to receive modelform_instance.cleaned_data['foreign key field'] in view?
Here is the situation:
I have a model as below:
class Permit(Model):
permit_option = BooleanField()
Permit model has two objects:
Permit.objects.create(permit_option=False) # id=1
Permit.objects.create(permit_option=True) # id=2
I have…

Amin Ba
- 1,603
- 1
- 13
- 38
1
vote
1 answer
MySQL row priority
I have a database table full of some really ugly and messy data. In a separate table, I have a cleaner version of the data and they are linked by an id, but I need to keep the messy dataset and can't overwrite it as I use it to check against data…

pedalpete
- 21,076
- 45
- 128
- 239