how to get all fields of related model in django instead of only id
models.py
from django.db import models
class SeekerRegister(models.Model):
seeker_name = models.CharField(max_length=32)
seeker_email = models.CharField(max_length=32)
class Social(models.Model):
social_links = models.CharField(max_length=256)
user = models.ForeignKey(access_models.SeekerRegister,on_delete=models.CASCADE,related_name='social',null=True,blank=True)
my query:
>>>obj=list(SeekerRegister.objects.values('social'))
>>>['social': 1, 'social': 2, 'social': 3]
expecting:
['social_links': 'facebook.com','user':1,'seeker_name':'a', 'social_links': 'twitter.com','user':2,'seeker_name':'b', 'social_links': 'linkedin.com','user':3,'seeker_name':'c']
when i am writing the above query i am getting only id of social model.
how can i get all fields both social_links and user instead.
please have a look into my code.
django
add a comment |
models.py
from django.db import models
class SeekerRegister(models.Model):
seeker_name = models.CharField(max_length=32)
seeker_email = models.CharField(max_length=32)
class Social(models.Model):
social_links = models.CharField(max_length=256)
user = models.ForeignKey(access_models.SeekerRegister,on_delete=models.CASCADE,related_name='social',null=True,blank=True)
my query:
>>>obj=list(SeekerRegister.objects.values('social'))
>>>['social': 1, 'social': 2, 'social': 3]
expecting:
['social_links': 'facebook.com','user':1,'seeker_name':'a', 'social_links': 'twitter.com','user':2,'seeker_name':'b', 'social_links': 'linkedin.com','user':3,'seeker_name':'c']
when i am writing the above query i am getting only id of social model.
how can i get all fields both social_links and user instead.
please have a look into my code.
django
1
Instead of getting objects of SeekerRegister get objects of Social model.Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20
add a comment |
models.py
from django.db import models
class SeekerRegister(models.Model):
seeker_name = models.CharField(max_length=32)
seeker_email = models.CharField(max_length=32)
class Social(models.Model):
social_links = models.CharField(max_length=256)
user = models.ForeignKey(access_models.SeekerRegister,on_delete=models.CASCADE,related_name='social',null=True,blank=True)
my query:
>>>obj=list(SeekerRegister.objects.values('social'))
>>>['social': 1, 'social': 2, 'social': 3]
expecting:
['social_links': 'facebook.com','user':1,'seeker_name':'a', 'social_links': 'twitter.com','user':2,'seeker_name':'b', 'social_links': 'linkedin.com','user':3,'seeker_name':'c']
when i am writing the above query i am getting only id of social model.
how can i get all fields both social_links and user instead.
please have a look into my code.
django
models.py
from django.db import models
class SeekerRegister(models.Model):
seeker_name = models.CharField(max_length=32)
seeker_email = models.CharField(max_length=32)
class Social(models.Model):
social_links = models.CharField(max_length=256)
user = models.ForeignKey(access_models.SeekerRegister,on_delete=models.CASCADE,related_name='social',null=True,blank=True)
my query:
>>>obj=list(SeekerRegister.objects.values('social'))
>>>['social': 1, 'social': 2, 'social': 3]
expecting:
['social_links': 'facebook.com','user':1,'seeker_name':'a', 'social_links': 'twitter.com','user':2,'seeker_name':'b', 'social_links': 'linkedin.com','user':3,'seeker_name':'c']
when i am writing the above query i am getting only id of social model.
how can i get all fields both social_links and user instead.
please have a look into my code.
django
django
edited Nov 14 '18 at 6:11
soubhagya
asked Nov 14 '18 at 5:51
soubhagyasoubhagya
968
968
1
Instead of getting objects of SeekerRegister get objects of Social model.Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20
add a comment |
1
Instead of getting objects of SeekerRegister get objects of Social model.Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20
1
1
Instead of getting objects of SeekerRegister get objects of Social model.
Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
Instead of getting objects of SeekerRegister get objects of Social model.
Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20
add a comment |
1 Answer
1
active
oldest
votes
You can try like this:
SeekerRegister.objects.values('social__social_link', 'id', 'seeker_name')
where social__social_link
is the social_link
and id
is user
Pleas check this SO Answer for more details.
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%2f53293923%2fhow-to-get-all-fields-of-related-model-in-django-instead-of-only-id%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can try like this:
SeekerRegister.objects.values('social__social_link', 'id', 'seeker_name')
where social__social_link
is the social_link
and id
is user
Pleas check this SO Answer for more details.
add a comment |
You can try like this:
SeekerRegister.objects.values('social__social_link', 'id', 'seeker_name')
where social__social_link
is the social_link
and id
is user
Pleas check this SO Answer for more details.
add a comment |
You can try like this:
SeekerRegister.objects.values('social__social_link', 'id', 'seeker_name')
where social__social_link
is the social_link
and id
is user
Pleas check this SO Answer for more details.
You can try like this:
SeekerRegister.objects.values('social__social_link', 'id', 'seeker_name')
where social__social_link
is the social_link
and id
is user
Pleas check this SO Answer for more details.
answered Nov 14 '18 at 6:13
ruddraruddra
15.1k32748
15.1k32748
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%2f53293923%2fhow-to-get-all-fields-of-related-model-in-django-instead-of-only-id%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
1
Instead of getting objects of SeekerRegister get objects of Social model.
Social.objects.values('social_links', 'user')
– Jagjeet Singh
Nov 14 '18 at 6:02
i want data from both models by joining them . please have a look into my expecting result
– soubhagya
Nov 14 '18 at 6:12
Oh! you edited the question later.
– Jagjeet Singh
Nov 14 '18 at 6:20