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.
40 lines
801 B
40 lines
801 B
from rest_framework.serializers import ModelSerializer
|
|
|
|
from .models import Location
|
|
|
|
|
|
class NestedLocationSerializer(ModelSerializer):
|
|
class Meta:
|
|
model = Location
|
|
|
|
fields = (
|
|
'id',
|
|
'name',
|
|
'children',
|
|
'parent',
|
|
'type',
|
|
'lft',
|
|
'rght',
|
|
'level',
|
|
'tree_id',
|
|
)
|
|
|
|
|
|
class LocationSerializer(ModelSerializer):
|
|
children = NestedLocationSerializer(many=True)
|
|
parent = NestedLocationSerializer()
|
|
|
|
class Meta:
|
|
model = Location
|
|
|
|
fields = (
|
|
'id',
|
|
'name',
|
|
'children',
|
|
'parent',
|
|
'type',
|
|
'lft',
|
|
'rght',
|
|
'level',
|
|
'tree_id',
|
|
)
|
|
|