django-orchestra-test/orchestra/apps/websites/serializers.py

28 lines
913 B
Python

from rest_framework import serializers
from orchestra.api.fields import OptionField
from orchestra.api.serializers import HyperlinkedModelSerializer
from orchestra.apps.accounts.serializers import AccountSerializerMixin
from .models import Website, Content
class ContentSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Content
fields = ('webapp', 'path')
def get_identity(self, data):
return '%s-%s' % (data.get('website'), data.get('path'))
class WebsiteSerializer(AccountSerializerMixin, HyperlinkedModelSerializer):
contents = ContentSerializer(required=False, many=True, allow_add_remove=True,
source='content_set')
options = OptionField(required=False)
class Meta:
model = Website
fields = ('url', 'name', 'port', 'domains', 'is_active', 'contents', 'options')
postonly_fileds = ('name',)