WebJun 4, 2016 · from rest_framework_recursive.fields import RecursiveField class LevelSerializer (serializers.ModelSerializer): type = serializers.SerializerMethodField () children = serializers.ListField (child=RecursiveField (), source='get_children') def get_type (self, instance): return "Level" class Meta: model = Level fields = ('type', 'name', … WebMar 19, 2016 · Every REST API I've ever seen that has writable endpoints has this kind of URL-based argument inference, so the fact that django-rest-framework doesn't seem to be able to do it at all seems strange. python
python - 具有多對多框架和中間模型的Django Rest框架 - 堆棧內 …
WebNov 16, 2024 · You can create a serializer for it like this: from rest_framework import serializers class OrderSerializer(serializers.ModelSerializer): class Meta: model = … WebDjango REST - FlexFields Flexible, dynamic fields and nested models for Django REST Framework serializers. Overview FlexFields (DRF-FF) for Django REST Framework is a package designed to provide a common baseline of functionality for dynamically setting fields and nested models within DRF serializers. budget car chania airport
How to use Serializers in the Django Python web framework
WebAug 6, 2015 · pip3 install djangorestframework-recursive I was able to do it like so: from rest_framework_recursive.fields import RecursiveField class MyModelRecursiveSerializer (serializers.Serializer): # your other fields children = serializers.ListField ( read_only=True, source='your_get_children_method', child=RecursiveField () ) WebApr 26, 2024 · serializer.data is a dictionary subclass (i.e. ReturnDict ), access it as you would a vanilla dictionary: id = serializer.data ['id'] Share Improve this answer Follow answered Apr 26, 2024 at 13:06 Moses Koledoye 76.7k 8 131 137 3 I would recommend id = serializer.data.get ('id', None) just in case. – Mateusz Knapczyk Apr 26, 2024 at 13:27 WebDec 3, 2024 · I must mention that I want to able to use depth option of nested serializer. I am using django 2.2.7 and rest framework 3.10.1. Edit. There may be some numbers of nested levels which it must be stopped using depth option, after some levels it must be flatten, so I wanted to able to use depth option along nested serializer. budget car chart