You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
from django.contrib.contenttypes.models import ContentType
|
|
from rest_framework.serializers import ModelSerializer
|
|
|
|
from .models import Location
|
|
|
|
|
|
class NestedLocationSerializer(ModelSerializer):
|
|
class Meta:
|
|
model = Location
|
|
|
|
fields = (
|
|
'children',
|
|
'id',
|
|
'level',
|
|
'lft',
|
|
'name',
|
|
'parent',
|
|
'rght',
|
|
'tree_id',
|
|
'type',
|
|
)
|
|
|
|
|
|
class LocationSerializer(ModelSerializer):
|
|
children = NestedLocationSerializer(many=True)
|
|
parent = NestedLocationSerializer()
|
|
|
|
class Meta:
|
|
model = Location
|
|
|
|
fields = (
|
|
'children',
|
|
'id',
|
|
'level',
|
|
'lft',
|
|
'name',
|
|
'parent',
|
|
'rght',
|
|
'tree_id',
|
|
'type',
|
|
)
|
|
|
|
|
|
class ContentTypeSerializer(ModelSerializer):
|
|
class Meta:
|
|
model = ContentType
|
|
|
|
fields = (
|
|
'app_label',
|
|
'id',
|
|
'model',
|
|
)
|
|
|