My problem is this:
In my app I have the following models inside the 'models.py'
class Carrera(models.Model):
nombre = models.CharField(max_length=50)
class Materia(models.Model):
nombre = models.CharField(max_length=50)
nivel = models.PositiveIntegerField()
carrera = models.ForeignKey(Carrera)
The serilizers.py
class Carrera_Serializer(serializers.ModelSerializer):
class Meta:
model = Carrera
fields = ('id', 'nombre')
class Materia_Serializer(serializers.ModelSerializer):
class Meta:
model = Materia
fields = ('nombre', 'nivel', 'carrera')
The urls are:
router = routers.DefaultRouter()
router.register(r'plan/mat', api.Materia_ViewSet)
router.register(r'plan/car', api.Carrera_ViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
]
The JSON shown when entering link is as follows:
{
"nombre": "Ing Civil I",
"nivel": 1,
"carrera": 1
},
And I would like you to show:
{
"nombre": "Ing Civil I",
"nivel": 1,
"carrera": {"nombre": "Ing Civil"
"url": "http://localhost:8000/plan/car/1/"
}
},