#31 API basic implementation Refactor
* reorganizes code into proper api/utils/serializer subclasses to keep serialization logic away from regular view logic
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 24.01.22
|
||||
|
||||
"""
|
||||
|
||||
from django.db.models import QuerySet
|
||||
|
||||
from api.utils.v1.serializer import AbstractModelAPISerializerV1
|
||||
from intervention.models import Intervention
|
||||
|
||||
|
||||
class InterventionAPISerializerV1(AbstractModelAPISerializerV1):
|
||||
model = Intervention
|
||||
|
||||
def compensations_to_json(self, qs: QuerySet):
|
||||
return list(
|
||||
qs.values(
|
||||
"id", "identifier", "title"
|
||||
)
|
||||
)
|
||||
|
||||
def extend_properties_data(self, entry):
|
||||
self.properties_data["responsible"] = self.responsible_to_json(entry.responsible)
|
||||
self.properties_data["legal"] = self.legal_to_json(entry.legal)
|
||||
self.properties_data["compensations"] = self.compensations_to_json(entry.compensations.all())
|
||||
self.properties_data["payments"] = self.payments_to_json(entry.payments.all())
|
||||
self.properties_data["deductions"] = self.deductions_to_json(entry.deductions.all())
|
||||
Reference in New Issue
Block a user