how to get all fields of related model in django instead of only id










0















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.










share|improve this question



















  • 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















0















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.










share|improve this question



















  • 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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












1 Answer
1






active

oldest

votes


















2














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.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    2














    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.






    share|improve this answer



























      2














      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.






      share|improve this answer

























        2












        2








        2







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 6:13









        ruddraruddra

        15.1k32748




        15.1k32748





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo