1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

Improve REST API with filters

This commit is contained in:
Yohann D'ANELLO
2020-03-11 11:15:03 +01:00
parent bc97eb1eb4
commit 417cd5da04
15 changed files with 78 additions and 36 deletions

View File

@ -1,6 +1,7 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from .serializers import ChangelogSerializer
@ -15,3 +16,5 @@ class ChangelogViewSet(viewsets.ModelViewSet):
"""
queryset = Changelog.objects.all()
serializer_class = ChangelogSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ['model', 'action', "instance_pk", 'user', 'ip',]

View File

@ -81,7 +81,7 @@ def save_object(sender, instance, **kwargs):
model = instance.__class__
fields = '__all__'
previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8")
previous_json = JSONRenderer().render(CustomSerializer(previous).data).decode("UTF-8") if previous else None
instance_json = JSONRenderer().render(CustomSerializer(instance).data).decode("UTF-8")
if previous_json == instance_json:

View File

@ -1,8 +0,0 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
app_name = 'logs'
# TODO User interface
urlpatterns = [
]