Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django URL Filter - DjangoCon US 2015 Lighting Talk

Django URL Filter - DjangoCon US 2015 Lighting Talk

A lighting talk I gave at DjangoCon US 2015 about a library I open-sourced Django URL Filter.

More information can be found in docs at bit.ly/django-url-filter.

Miroslav Shubernetskiy

September 09, 2015
Tweet

More Decks by Miroslav Shubernetskiy

Other Decks in Programming

Transcript

  1. Use Cases • Pagination
 (lots of data) • API
 (bulk

    operations) • Filtering logic
 client-side
  2. 1. Human-Friendly URLs • ?id=1 • ?id!=1 # negated •

    ?id__in=1,2,3 • ?name__contains=Django
  3. 2. Safe Filtering • ?id=1 (IntegerField) • ?id__in=1,2,3 (IntegerField) •

    ?username=django (CharField) • ?joined__year=2015 (Int…Field)
  4. 4. Data-source Agnostic • Django ORM • SQLAlchemy (in progress)

    • <etc> Parsing URL and filtering is decoupled
  5. DRF Integration class UserViewSet(ModelViewSet):
 queryset = User.objects.all()
 serializer_class = UserSerializer


    filter_backends = [DjangoFilterBackend]
 filter_fields = ['username', 'email']
  6. Vanilla Usage class UserFS(ModelFilterSet):
 class Meta(object):
 model = User q

    = QueryDict(‘username__icontains=django’)
 fs = UserFS(data=query,
 queryset=User.objects.all())
 filtered_users = fs.filter()