views:

93

answers:

2

Hi,

Does anybody know how to get the selected item of a dropdown menu from within a clean method in a modelform object, before the object has been saved? I have tried the following:

def clean_something(self):
   dropdown = self.cleaned_data.get('dropdown')

where 'dropdown' is the field representing the dropdown menu, but this doesn't seem to work.

Any ideas?

Cheers, Charles

A: 

You will find it in, self.data

def clean_something(self):
   dropdown = self.data.get('dropdown')
simplyharsh
Thanks harshh, but self.data.get gives me the primary key, and not the value that's shown in the dropdown menu. Of course I can do a lookup, but I was wondering if there is an easier way to get the value straight from the form.
A: 

Sorry Guys, I should have tested this more thoroughly... The following gives me the value I was looking for!

def clean_something(self):
   dropdown = u'%s' % self.cleaned_data.get('dropdown')