serializers.py 702 B

12345678910111213141516171819202122232425262728
  1. from rest_framework import serializers
  2. from suitablephones.models import Bluetooth, Camera, Device
  3. class CameraSerializer(serializers.ModelSerializer):
  4. class Meta:
  5. model = Camera
  6. exclude = ["id"]
  7. class BluetoothSerializer(serializers.ModelSerializer):
  8. class Meta:
  9. model = Bluetooth
  10. exclude = ["id"]
  11. class ScreenSerializer(serializers.ModelSerializer):
  12. class Meta:
  13. model = Screen
  14. exclude = ["id"]
  15. class DeviceSerializer(serializers.ModelSerializer):
  16. bluetooth = BluetoothSerializer(many=False, read_only=True)
  17. cameras = CameraSerializer(many=True, read_only=True)
  18. class Meta:
  19. model = Device
  20. exclude = ["id"]