Как сделать некоторые фильтры обязательными в deliciouspie?

class LinguistResource(ModelResource):

    class Meta:
        model = Linguist
        queryset = Linguist.objects.all()
        resource_name = 'linguists_by_language'
        filtering = {
            "language": ('exact', ),
        }

Можно ли сделать фильтр "язык" обязательным?

Моя цель - поднять ошибку, если в параметрах GET отсутствует ключ "язык"


person dixon    schedule 24.02.2012    source источник


Ответы (1)


Вы можете поймать это, переопределив build_filters:

from tastypie.exceptions import BadRequest

def build_filters(self, filters=None):
    if 'language' not in filters:
         raise BadRequest("missing language param") # or maybe create your own exception
    return super(LinguistResource, self).build_filters(filters)
person JamesO    schedule 24.02.2012