mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-10 23:02:47 +02:00
Enable filtering and sorting on all API views
This commit is contained in:
@@ -16,9 +16,14 @@ class AccountGroupViewSet(viewsets.ModelViewSet):
|
||||
queryset = AccountGroup.objects.all()
|
||||
serializer_class = AccountGroupSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'owner': ['exact'],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
|
||||
def get_queryset(self):
|
||||
return AccountGroup.objects.all().order_by("id")
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
@@ -34,11 +39,22 @@ class AccountViewSet(viewsets.ModelViewSet):
|
||||
queryset = Account.objects.all()
|
||||
serializer_class = AccountSerializer
|
||||
pagination_class = CustomPageNumberPagination
|
||||
filterset_fields = {
|
||||
'name': ['exact', 'icontains'],
|
||||
'group': ['exact', 'isnull'],
|
||||
'currency': ['exact'],
|
||||
'exchange_currency': ['exact', 'isnull'],
|
||||
'is_asset': ['exact'],
|
||||
'is_archived': ['exact'],
|
||||
'owner': ['exact'],
|
||||
}
|
||||
search_fields = ['name']
|
||||
ordering_fields = '__all__'
|
||||
ordering = ['id']
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
Account.objects.all()
|
||||
.order_by("id")
|
||||
.select_related("group", "currency", "exchange_currency")
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user