#23940: problem when i access related object
----------------------------------------------+--------------------
Reporter: zhiyajun11 | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------------------+--------------------
Hi guys, when i try to access the related model of a model who has a field
named exact by related-manager, a 'exact=true' limit will be add to the
sql automatically. As show below:
My models is:
{{{
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
#pub_date = models.DateTimeField('date published')
pub_date = models.IntegerField()
exact = models.NullBooleanField()
#exact = models.IntegerField(default=0)
def was_published_recently(self):
return self.pub_date >= timezone.now() -
datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, related_name = 'choices')
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
}}}
The shell command is:
{{{
In [1]: from polls.models import Question
In [2]: Question.objects.all()
Out[2]: [<Question: Question object>, <Question: Question object>]
In [3]: q = Question.objects.get(pk=1)
In [4]: q
Out[4]: <Question: Question object>
In [5]: q.choices.all()
Out[5]: []
In [6]: from django.db import connection
In [7]: connection.queries[-1]
Out[7]:
{u'sql': u'QUERY = u'SELECT "polls_choice"."id",
"polls_choice"."question_id", "polls_choice"."choice_text",
"polls_choice"."votes" FROM "polls_choice" INNER JOIN "polls_question" ON
( "polls_choice"."question_id" = "polls_question"."id" ) WHERE
"polls_question"."exact" = %s LIMIT 21' - PARAMS = (True,)',
u'time': u'0.000'}
}}}
Ps: this problem also show up on django1.6.
--
Ticket URL: <https://code.djangoproject.com/ticket/23940>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.775a48ac12a61706f6de5abc42c5997d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.