Skip to content

Commit

Permalink
fix serializers fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinaascari committed May 16, 2024
1 parent a2520f5 commit 3f45b0f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions certego_saas/ext/upload/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ class __AbstractBISerializer:
environment: Field
timestamp: Field

class Meta:
fields = [
"application",
"environment",
"timestamp",
]

@staticmethod
def to_elastic_dict(data, index):
return {
Expand Down Expand Up @@ -81,6 +74,7 @@ def __repr__(self):
except ImportError:
from django.db.models import Index, JSONField, Model
from django.db.models import fields as django_fields
from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

class BIDocument(__BIDocumentInterface, Model):
Expand All @@ -94,7 +88,14 @@ class Meta:
indexes = [Index(fields=["index"]), Index(fields=["timestamp"])]

class BISerializer(__AbstractBISerializer, ModelSerializer):
...
index = SerializerMethodField(method_name="get_index")

class Meta:
fields = [
"application",
"environment",
"timestamp",
]

else:
from rest_framework_mongoengine.serializers import DocumentSerializer
Expand All @@ -112,7 +113,11 @@ class BIDocument(__BIDocumentInterface, Document):
class BISerializer(__AbstractBISerializer, DocumentSerializer):
class Meta:
model = BIDocument
fields = __AbstractBISerializer.Meta.fields
fields = [
"application",
"environment",
"timestamp",
]

def to_representation(self, instance: BIDocument):
data = super().to_representation(instance)
Expand Down

0 comments on commit 3f45b0f

Please sign in to comment.