Fakultas Ilmu Komputer UI

Commit 06ad0adf authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[Bugfix] Generalized related ID field on History creation method

parent 9a170c4e
from django.contrib import admin from django.contrib import admin
from apps.accounts.models import Account from apps.accounts.models import Account, AccountHistory
admin.site.register(Account) admin.site.register(Account)
admin.site.register(AccountHistory)
from django.contrib import admin from django.contrib import admin
from apps.cases.models import ( from apps.cases.models import (
CaseSubject, CaseSubject,
CaseSubjectHistory,
InvestigationCase, InvestigationCase,
InvestigationCaseHistory,
MonitoringCase, MonitoringCase,
MonitoringCaseHistory,
) )
admin.site.register(CaseSubject) admin.site.register(CaseSubject)
admin.site.register(CaseSubjectHistory)
admin.site.register(InvestigationCase) admin.site.register(InvestigationCase)
admin.site.register(InvestigationCaseHistory)
admin.site.register(MonitoringCase) admin.site.register(MonitoringCase)
admin.site.register(MonitoringCaseHistory)
...@@ -70,11 +70,11 @@ class HistoryEnabledModel(SoftDeleteModel): ...@@ -70,11 +70,11 @@ class HistoryEnabledModel(SoftDeleteModel):
instance_dict["object_id"] = self.id instance_dict["object_id"] = self.id
instance_dict["action_type"] = action instance_dict["action_type"] = action
if self.history_class._meta.get_field("author").get_internal_type() == "UUIDField": if self.history_class._meta.get_field("author").get_internal_type() == "ForeignKey":
self.history_class.objects.create(**instance_dict, author=author)
else:
author_id = None if author is None else author.id author_id = None if author is None else author.id
self.history_class.objects.create(**instance_dict, author=author_id) self.history_class.objects.create(**instance_dict, author=author_id)
else:
self.history_class.objects.create(**instance_dict, author=author)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
action = ACTIVITY_TYPE_CREATE if self._state.adding else ACTIVITY_TYPE_EDIT action = ACTIVITY_TYPE_CREATE if self._state.adding else ACTIVITY_TYPE_EDIT
......
...@@ -47,8 +47,8 @@ class LogAPIView(ListAPIView): ...@@ -47,8 +47,8 @@ class LogAPIView(ListAPIView):
)) ))
def get(self, request): def get(self, request):
serializer_data = []
logs_querysets = self.get_queryset(request) logs_querysets = self.get_queryset(request)
logs_querysets = sorted(logs_querysets, key=lambda x: x.recorded_at, reverse=True)
paginator = PageNumberPagination() paginator = PageNumberPagination()
context = paginator.paginate_queryset(logs_querysets, request) context = paginator.paginate_queryset(logs_querysets, request)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment