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.

soubhagya
  • 788
  • 2
  • 12
  • 37

1 Answers1

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.

ruddra
  • 50,746
  • 7
  • 78
  • 101