I'm making a API with django rest framework, but the JSON has the the categoria's id of categoria model, the foreignkey, I want show the categoria's name equals the model's id
class Establecimiento(models.Model):
nombre= models.CharField(max_length = 140)
categoria = models.ForeignKey(Categoria)
ciudad = models.ForeignKey(Ciudad)
def __unicode__(self):
return self.nombre
class Categoria(models.Model):
titulo = models.CharField(max_length = 140)
I have a file serializers.py a views.py whit ViewSet
class EstablecimientoSerializer(serializers.ModelSerializer):
# establecimiento = Establecimineto.objects.values('categoira__titulo')
class Meta:
model = Establecimiento.objects.select_related('categoria')
# model = Establecimiento
fields = ('nombre','categoria',)
#
class EstablecimientoViewSet(viewsets.ModelViewSet):
# queryset = Establecimiento.objects.all()
queryset = Establecimiento.objects.values('nombre','categoria__titulo')
serializer_class = EstablecimientoSerializer
Then when I make the query in the views.py the JSON result only show the fields null where I should make the query for that the JSON resulting not show id the Foreignkey