self.cleaned_data.get not working with integer field
I have a pretty basic definition within my forms.py to pull data from my submitted form. Something I have done with other apps, but for some reason, it is not working at the moment. I feel like I'm overlooking something. Whenever I print(image_height) I get None. models.py height_field = models.IntegerField(default=1200) forms.py class PostForm(ModelForm): class Meta: model = Post fields = ['user', 'title', 'content', 'post_image', 'height_field', 'width_field', 'draft', 'publish'] def clean_post_image(self): post_image = self.cleaned_data["post_image"] image_height = self.cleaned_data.get("height_field") print(image_height) return post_image
If you want to validate your form field with respect to other field, you should do that in your clean method. From the docs, The form subclass’s clean() method can perform validation that requires access to multiple form fields. This is where you might put in checks such as “if field A is supplied, field B must contain a valid email address”. This method can return a completely different dictionary if it wishes, which will be used as the cleaned_data. You could do something like this, def clean(self, cleaned_data): post_image = cleaned_data.get("post_image") height_image = cleaned_data.get("height_image") #do_your_thing return cleaned_data
Wagtail 0.8.6 - submit for moderation - email notification to moderators group members
Django Tastypie: Output JSON by defaut, but support other formats too?
Good way to deploy a django app with an asynchronous script running outside of the app
How to avoid SECRET_KEY error when starting Celery using Supervisor?
What is the way to set ipython notebook server parameters when running notebook with django-extensions?
How to dynamically chain another filter to an existing queryset?
Django and the limits of SQLite
Some TextFields created in database with NOT NULL YES/NO
django admin: Adding a textarea and a button that invokes a function
Sorl thumbnail not opening image in template (Django)
Generating an access token programatically with Django OAuth2 Toolkit
Retrieving model class dynamically in CBV
How to get authenticated user on serializer class for validation
Pattern for Django model instance method + equivalent QuerySet filter?
Base template for all apps in Django
#method_decorator with login_required and permission_required