Answer the question
In order to leave comments, you need to log in
Why doesn't select_related() work in Django 1.6?
There are models in which there are fields:
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, primary_key=True, unique=True, related_name='user_id')
...
class Comments(MPTTModel):
...
user = models.ForeignKey(Profile, related_name='id_user_com')
...
c = Comments.objects.select_related('id_user_com__user_id').get(id=4)
print c.username
AttributeError: 'Comment' objects has no attribute 'username'
serializers.serialize('json', c, fields=('id','text','level','rating','username'))
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