How to save Foreign Key values in DJANGO REST?What is a “slug” in Django?How to write a Custom field Validation for ModelSerializers in Django Rest Framework(DRF) similar to Form Validation in Django?save() prohibited to prevent data loss due to unsaved related object 'postid'Posting a foreign key relationship in Django Rest FrameworkSerializing custom related field in DRFDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerdjango rest framework and forms: How to doDjango Model Issue In Multilevel Inheritance.How to implement update_or_create inside create method of ModelSerializerf string interpolation syntax error python3.6How to check if Django Signal works?
Would it be a copyright violation if I made a character’s full name refer to a song?
How are the Zhentarim and Black Fist related?
In the Marvel universe, can a human have a baby with any non-human?
What does "play with your toy’s toys" mean?
Why do some professors with PhDs leave their professorships to teach high school?
How was Hillel permitted to go to the skylight to hear the shiur
How to make clear to people I don't want to answer their "Where are you from?" question?
Accidentals and ties
Are all instances of trolls turning to stone ultimately references back to Tolkien?
How many people are necessary to maintain modern civilisation?
Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback
Find the diameter of a word graph
Links to webpages in books
How is hair tissue mineral analysis performed?
Should developer taking test phones home or put in office?
What's currently blocking the construction of the wall between Mexico and the US?
Is there a maximum distance from a planet that a moon can orbit?
Can ADFS connect to other SSO services?
Can Ogre clerics use Purify Food and Drink on humanoid characters?
C-152 carb heat on before landing in hot weather?
Why do some games show lights shine thorugh walls?
What was the Shuttle Carrier Aircraft escape tunnel?
Is using weak login credentials always bad?
Folding basket - is there such a thing?
How to save Foreign Key values in DJANGO REST?
What is a “slug” in Django?How to write a Custom field Validation for ModelSerializers in Django Rest Framework(DRF) similar to Form Validation in Django?save() prohibited to prevent data loss due to unsaved related object 'postid'Posting a foreign key relationship in Django Rest FrameworkSerializing custom related field in DRFDjango-Rest-Framework - How to serialize queryset from an unrelated model as nested serializerdjango rest framework and forms: How to doDjango Model Issue In Multilevel Inheritance.How to implement update_or_create inside create method of ModelSerializerf string interpolation syntax error python3.6How to check if Django Signal works?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Let's say i have models like follow.
class Department(models.Model):
name = models.CharField(max_length=255)
class Student(models.Model):
department = models.Foreignkey(Department, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
Now i need to set Department(which is created already)
of the Student
whenever i create the student instance
.
which is best practice
i) Sending the department id in URI like `departments/pk/students`
ii) sending department id in body parameter
django-rest-framework python-3.6 django-serializer django-2.1
add a comment |
Let's say i have models like follow.
class Department(models.Model):
name = models.CharField(max_length=255)
class Student(models.Model):
department = models.Foreignkey(Department, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
Now i need to set Department(which is created already)
of the Student
whenever i create the student instance
.
which is best practice
i) Sending the department id in URI like `departments/pk/students`
ii) sending department id in body parameter
django-rest-framework python-3.6 django-serializer django-2.1
department id in the body and the endpoint should look like/student/
(not adding department in URL and keeping it simple) with an HTTPPOST
– Aarif
Mar 25 at 9:54
add a comment |
Let's say i have models like follow.
class Department(models.Model):
name = models.CharField(max_length=255)
class Student(models.Model):
department = models.Foreignkey(Department, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
Now i need to set Department(which is created already)
of the Student
whenever i create the student instance
.
which is best practice
i) Sending the department id in URI like `departments/pk/students`
ii) sending department id in body parameter
django-rest-framework python-3.6 django-serializer django-2.1
Let's say i have models like follow.
class Department(models.Model):
name = models.CharField(max_length=255)
class Student(models.Model):
department = models.Foreignkey(Department, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
Now i need to set Department(which is created already)
of the Student
whenever i create the student instance
.
which is best practice
i) Sending the department id in URI like `departments/pk/students`
ii) sending department id in body parameter
django-rest-framework python-3.6 django-serializer django-2.1
django-rest-framework python-3.6 django-serializer django-2.1
asked Mar 25 at 9:34
HariHaraSudhanHariHaraSudhan
5211 gold badge6 silver badges23 bronze badges
5211 gold badge6 silver badges23 bronze badges
department id in the body and the endpoint should look like/student/
(not adding department in URL and keeping it simple) with an HTTPPOST
– Aarif
Mar 25 at 9:54
add a comment |
department id in the body and the endpoint should look like/student/
(not adding department in URL and keeping it simple) with an HTTPPOST
– Aarif
Mar 25 at 9:54
department id in the body and the endpoint should look like
/student/
(not adding department in URL and keeping it simple) with an HTTP POST
– Aarif
Mar 25 at 9:54
department id in the body and the endpoint should look like
/student/
(not adding department in URL and keeping it simple) with an HTTP POST
– Aarif
Mar 25 at 9:54
add a comment |
2 Answers
2
active
oldest
votes
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
add a comment |
in this case, It'd be better to send department id in the body and keep the endpoint simple as
base/api/student/
make an HTTP POST to this endpoint
"department_id":"",
.
.
by taking a look at this endpoint this clearly shows endpoint for operations involving student
object, I'd say it's more close to REST
standards.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334807%2fhow-to-save-foreign-key-values-in-django-rest%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
add a comment |
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
add a comment |
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
It is always better to send the sensitive data like ids as Post request instead of passing as URL args. if you really want to pass data in URL then please use slugs instead of ID.
also, you can use DRF model serializer to save the data
answered Mar 25 at 9:42
Nakul NarayananNakul Narayanan
6177 silver badges11 bronze badges
6177 silver badges11 bronze badges
add a comment |
add a comment |
in this case, It'd be better to send department id in the body and keep the endpoint simple as
base/api/student/
make an HTTP POST to this endpoint
"department_id":"",
.
.
by taking a look at this endpoint this clearly shows endpoint for operations involving student
object, I'd say it's more close to REST
standards.
add a comment |
in this case, It'd be better to send department id in the body and keep the endpoint simple as
base/api/student/
make an HTTP POST to this endpoint
"department_id":"",
.
.
by taking a look at this endpoint this clearly shows endpoint for operations involving student
object, I'd say it's more close to REST
standards.
add a comment |
in this case, It'd be better to send department id in the body and keep the endpoint simple as
base/api/student/
make an HTTP POST to this endpoint
"department_id":"",
.
.
by taking a look at this endpoint this clearly shows endpoint for operations involving student
object, I'd say it's more close to REST
standards.
in this case, It'd be better to send department id in the body and keep the endpoint simple as
base/api/student/
make an HTTP POST to this endpoint
"department_id":"",
.
.
by taking a look at this endpoint this clearly shows endpoint for operations involving student
object, I'd say it's more close to REST
standards.
answered Mar 25 at 10:03
AarifAarif
6127 silver badges18 bronze badges
6127 silver badges18 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334807%2fhow-to-save-foreign-key-values-in-django-rest%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
department id in the body and the endpoint should look like
/student/
(not adding department in URL and keeping it simple) with an HTTPPOST
– Aarif
Mar 25 at 9:54