Skip to content

using id with filter_class #14

@whoisearth

Description

@whoisearth

I'm attempting to use a django filter while continuing using the encrypted id.

I can do this -

http://localhost:8000/api/v1/widget/?id=3

but I can't do this -

http://localhost:8000/api/v1/widget/?id=zspnn6wva2rd47z44jo65bi6iy

doing so generates the following error:

invalid literal for int() with base 10: 'zspnn6wva2rd47z44jo65bi6iy'

which makes sense because it's expecting an integer.

I'm using django-filter like so:

class WidgetFilter(django_filters.FilterSet):
    id = django_filters.CharFilter(name='id', lookup_type='exact')
    name = django_filters.CharFilter(name='username', lookup_type='exact')
    list = django_filters.CharFilter(name='list__name', lookup_type='exact')

    class Meta:
        model = Widget
        fields = ['id', 'username', 'list__name']

When I query the actual ID it does return the encrypted value and I can query like this:

http://localhost:8000/api/v1/widget/zspnn6wva2rd47z44jo65bi6iy/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions