Tengo el codigo
# API DQO
class SampleSerializer(serializers.ModelSerializer):
class Meta:
model = models.Sample
fields = ['id']
class LoteDQOSerializer(serializers.ModelSerializer):
class Meta:
sample_r = SampleSerializer(many=True, read_only=True)
model = models.LoteDQO
fields = ['muestra_id', 'sample_r']
class DQO5Serializer(serializers.ModelSerializer):
lote_r = LoteDQOSerializer(many=True, read_only=True)
class Meta:
model = models.DQO5
fields = ['id', 'fecha', 'rcr', 'lote_r']
class DQO5ViewSet(ModelViewSet):
queryset = models.DQO5.objects.all()
serializer_class = AlbumSerializer
pero solo recibo
HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept
[ { "id": 1, "fecha": "2016-11-10", "rcr": 100.0064 }, { "id": 2, "fecha": "2016-11-22", "rcr": 92.928 },
Es decir esperaba los campos id del lote y la muestra.
Mis modelos son:
class LoteDQO(BaseBatch):
# Relación genérica al sample
param_samples = GenericRelation('common.ParamSampleBatch',
related_query_name='dqo_batch')
def __str__(self):
return f"{self.fecha}"
@atomic
def unlink_sample(self, sample):
# Eliminar todos los detalles
try:
sample.dqo5.delete()
except DQO5.DoesNotExist:
pass
class Sample(models.Model):
class Meta:
unique_together = ('control', 'empresa')
control = models.CharField(max_length=30, db_index=True)
empresa = models.ForeignKey(Company, on_delete=models.PROTECT)
dqo_aplica = models.BooleanField(default=False)
dqo = models.ForeignKey('hibasa_app.LoteDQO', null=True, blank=True,
related_name='muestras', on_delete=models.SET_NULL)
Control rutinario
class DQO5(models.Model):
muestra = models.OneToOneField('Muestra', on_delete=models.CASCADE, related_name="lote_r")
rcr = models.FloatField(
verbose_name='RECOBRO criterio 90-110% recuperacion')