开源软件名称:miki725/django-url-filter开源软件地址:https://github.com/miki725/django-url-filter开源编程语言:Python 99.0%开源软件介绍:Django URL FilterDjango URL Filter provides a safe way to filter data via human-friendly URLs.
OverviewThe main goal of Django URL Filter is to provide an easy URL interface for filtering data. It allows the user to safely filter by model attributes and also allows to specify the lookup type for each filter (very much like Django's filtering system in ORM). For example the following will retrieve all items where the id is
example.com/listview/?id=5&title__contains=foo In addition to basic lookup types, Django URL Filter allows to
use more sophisticated lookups such as example.com/listview/?id__in=1,2,3&created__year=2013 Requirements
InstallingEasiest way to install this library is by using $ pip install django-url-filter Usage ExampleTo make example short, it demonstrates Django URL Filter integration with Django REST Framework but it can be used without DRF (see below). from url_filter.integrations.drf import DjangoFilterBackend class UserViewSet(ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer filter_backends = [DjangoFilterBackend] filter_fields = ['username', 'email'] Alternatively filterset can be manually created and used directly to filter querysets: from django.http import QueryDict from url_filter.filtersets import ModelFilterSet class UserFilterSet(ModelFilterSet): class Meta(object): model = User query = QueryDict('email__contains=gmail&joined__gt=2015-01-01') fs = UserFilterSet(data=query, queryset=User.objects.all()) filtered_users = fs.filter() Above will automatically allow the use of all of the Django URL Filter features. Some possibilities: # get user with id 5 example.com/users/?id=5 # get user with id either 5, 10 or 15 example.com/users/?id__in=5,10,15 # get user with id between 5 and 10 example.com/users/?id__range=5,10 # get user with username "foo" example.com/users/?username=foo # get user with username containing case insensitive "foo" example.com/users/?username__icontains=foo # get user where username does NOT contain "foo" example.com/users/?username__icontains!=foo # get user who joined in 2015 as per user profile example.com/users/?profile__joined__year=2015 # get user who joined in between 2010 and 2015 as per user profile example.com/users/?profile__joined__range=2010-01-01,2015-12-31 # get user who joined in after 2010 as per user profile example.com/users/?profile__joined__gt=2010-01-01 Features
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论