I'm using an autocomplete within a form. The forms save doesn't seem to want to properly take in my hidden field.
The autocomplete shows a name: for instance 'Steve Butabi'. Its supposed to be sending a username. The username is 'stevebutabi'. Upon inspecting the input value. The username 'stevebutabi' properly shows. But within the POST, manager : 'Steve Butabi'
shows. And I get a Exception Type: DoesNotExist
. I need the hidden username, not the string it's presenting. I know whats happening, I just don't know how to fix it.
So I guess what I'm asking: is there a way to ignore the clean function within a Django form?
forms.py
manager = forms.CharField(max_length=200, required=True, widget=forms.TextInput(attrs={'class':'input-text','id':'id_managerbox'}))
def clean(self):
if not 'manager' in self.cleaned_data:
raise forms.ValidationError('You must supply a manager for this fund.')
return self.cleaned_data
def save(self, request):
if self.is_valid():
if self.cleaned_data['manager']:
manager = ManagerProfile.objects.get(user__username=self.cleaned_data['manager'])
# I've also tried :
manager = ManagerProfile.objects.get(user__username=request.POST['manager'])
...
ManagesFund.objects.get(manager=manager).save()
Javascript
$(document).ready(function() {
$.get('/autocomplete/managers/', function(data) {
var completions = new Array();
var dict = JSON.parse(data, function(key, value) {
completions.push(key);
return value;
});
$('#id_managerbox').autocomplete({
source: completions,
minLength: 2,
select: function(event, ui) {
$('#id_manager').val(dict[ui.item.value]);
}
});
});
});
Template
<input type="hidden" name="manager" id="id_manager" />
{{ form.manager }}
Thanks in advance.