[Django]-Django KeyError when getting an object with a keyword for a field name

3👍

Not tested:

Collection.objects.filter(
    name__exact='name', 
    type__exact='library', 
    owner__exact=owner, 
    parent__exact=parent)

Query docs: http://docs.djangoproject.com/en/dev/topics/db/queries/

Also consider naming your field differently, mainly not with the same name as a builtin.

👤miku

0👍

OK it turns out the problem was elsewhere. I was doing this in a form and thus using the self.cleaned_data dictionary of input values.

I was attempting to retrieve self.cleaned_data['type'] where in my previous simplification I stated the string ‘library’. This was not in fact in the cleaned data of the form and thus threw a KeyError.

Leave a comment