У меня 3 модели
class Camera(models.Model):
CameraId = models.AutoField(primary_key=True, db_column='CameraId')
CameraName = models.CharField(max_length=50)
class DeviceType(models.Model):
DeviceTypeId = models.AutoField(primary_key=True, db_column='DeviceTypeId')
DeviceType = models.CharField(max_length=50)
class Device(models.Model):
DeviceId = models.AutoField(primary_key=True, db_column='DeviceId')
DeviceName = models.CharField(max_length=50)
CameraId = models.ForeignKey(Camera, on_delete=models.CASCADE, db_column='CameraId',
related_name='cameras')
DeviceTypeId = models.ForeignKey(DeviceType, on_delete=models.CASCADE, db_column='DeviceTypeId')
Мне нужен результат сериализации JSON данных устройства, связанных с устройством
{
'DeviceId' : DeviceId ,
'DeviceName' : DeviceName ,
'CameraId' : CameraId,
'CameraName': CameraName ,
'DeviceTypeId' :DeviceTypeId ,
'DeviceType' :DeviceType
}
Как я могу это сделать?