Skip to content

Commit

Permalink
[1.1.X] Fixed #12024: Changed admin code to avoid raising an exceptio…
Browse files Browse the repository at this point in the history
…n when a field listed

in raw_id_fields has limit_choices_to specified as a Q object.

Tweaked a test to trigger the condition and verify the fix.

Finally, documented that limit_choices_to specified as a Q object has no effect
on the choices available for fields listed in raw_id_fields, and removed another
incorrect note that claimed limit_choices_to had no effect on inlines in the admin. 

r12728 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12729 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
kmtracey committed Mar 8, 2010
1 parent 758123a commit 75b10c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django/contrib/admin/widgets.py
Expand Up @@ -129,7 +129,7 @@ def render(self, name, value, attrs=None):

def base_url_parameters(self):
params = {}
if self.rel.limit_choices_to:
if self.rel.limit_choices_to and hasattr(self.rel.limit_choices_to, 'items'):
items = []
for k, v in self.rel.limit_choices_to.items():
if isinstance(v, list):
Expand Down
8 changes: 4 additions & 4 deletions docs/ref/models/fields.txt
Expand Up @@ -844,10 +844,10 @@ define the details of how the relation works.
current date/time to be chosen.

Instead of a dictionary this can also be a :class:`~django.db.models.Q`
object for more :ref:`complex queries <complex-lookups-with-q>`.

``limit_choices_to`` has no effect on the inline FormSets that are created
to display related objects in the admin.
object for more :ref:`complex queries <complex-lookups-with-q>`. However,
if ``limit_choices_to`` is a :class:`~django.db.models.Q` object then it
will only have an effect on the choices available in the admin when the
field is not listed in ``raw_id_fields`` in the ``ModelAdmin`` for the model.

.. attribute:: ForeignKey.related_name

Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/admin_widgets/models.py
Expand Up @@ -49,7 +49,7 @@ def __unicode__(self):
return self.name

class Event(models.Model):
band = models.ForeignKey(Band)
band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0))
start_date = models.DateField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
description = models.TextField(blank=True)
Expand Down

0 comments on commit 75b10c9

Please sign in to comment.