Answer the question
In order to leave comments, you need to log in
Django-restf-framework, what is the correct HTTP POST method to add data to a model with a ForeignKey?
I started to study djangorestframework - I need to write an API for the site. The official tutorial is simple and quickly passed, then closer to reality I created two simple connected (one-to-many) models:
class ModelA(models.Model):
...
class ModelB(models.Model):
modela = models.ForeignKey(ModelA)
...
class ModelASerializater(serializaters.HyperLinkModelSerialzater):
class Meta:
model = ModelA
fields = (...)
class ModelBSerializater(serializaters.HyperLinkModelSerialzater):
class Meta:
model = ModelB
fields = (...)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question