tags:

views:

69

answers:

2

I wish to get an object in the following fashion:

Collection.objects.get(name='name', type='library', owner=owner, parent=parent)

Unfortunately type is a keyword as thus creates the following error:

KeyError at /forms/create_library
type

Is there a way to disambiguate the meaning of the word type to allow me to specify a field of that name?

A: 

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.

The MYYN
This does not seem to resolve the error, but as everyone has mentioned I will change the name of the field name to a more suitable choice.
Marcus Whybrow
A: 

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.

Marcus Whybrow