Пример #1
0
class CountsSerializer(DynamicEphemeralSerializer):
    class Meta:
        name = 'counts'

    values = DynamicField(field_type=list)
    count = CountField('values', unique=False)
    unique_count = CountField('values')
Пример #2
0
class LocationSerializer(DynamicModelSerializer):
    class Meta:
        defer_many_relations = False
        model = Location
        name_field = 'name'
        name = 'location'
        fields = ('id', 'name', 'users', 'user_count', 'address', 'cats',
                  'friendly_cats', 'bad_cats', 'document')

    document = DynamicFileField(allow_null=False, deferred=True)
    users = DynamicRelationField('UserSerializer',
                                 source='user_set',
                                 many=True,
                                 deferred=True)
    user_count = CountField('users', required=False, deferred=True)
    address = DynamicField(source='blob', required=False, deferred=True)
    cats = DynamicRelationField('CatSerializer',
                                source='cat_set',
                                many=True,
                                deferred=True)
    friendly_cats = DynamicRelationField('CatSerializer',
                                         many=True,
                                         deferred=True)
    bad_cats = DynamicRelationField('CatSerializer',
                                    source='annoying_cats',
                                    many=True,
                                    deferred=True)
Пример #3
0
class LocationSerializer(DynamicModelSerializer):
    class Meta:
        defer_many_relations = False
        model = Location
        name = 'location'
        fields = ('id', 'name', 'users', 'user_count', 'address', 'cats',
                  'friendly_cats', 'bad_cats')

    users = DynamicRelationField('UserSerializer',
                                 source='user_set',
                                 many=True,
                                 deferred=True)
    user_count = CountField('users', required=False, deferred=True)
    address = DynamicField(source='blob', required=False, deferred=True)
    cats = DynamicRelationField('CatSerializer',
                                source='cat_set',
                                many=True,
                                deferred=True)
    friendly_cats = DynamicRelationField('CatSerializer',
                                         many=True,
                                         deferred=True)
    bad_cats = DynamicRelationField('CatSerializer',
                                    source='annoying_cats',
                                    many=True,
                                    deferred=True)

    def filter_queryset(self, query):
        return query.exclude(name='Atlantis')