Fixed #14880 - raw_id_fields in admin does not work when limit_choices_to dictionary has value=False
Thanks to smallming for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15348 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c24bdf044b
commit
655d5afea9
|
@ -102,6 +102,9 @@ def url_params_from_lookup_dict(lookups):
|
||||||
for k, v in lookups.items():
|
for k, v in lookups.items():
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
v = u','.join([str(x) for x in v])
|
v = u','.join([str(x) for x in v])
|
||||||
|
elif isinstance(v, bool):
|
||||||
|
# See django.db.fields.BooleanField.get_prep_lookup
|
||||||
|
v = ('0', '1')[v]
|
||||||
else:
|
else:
|
||||||
v = unicode(v)
|
v = unicode(v)
|
||||||
items.append((k, v))
|
items.append((k, v))
|
||||||
|
|
|
@ -187,17 +187,27 @@ class Actor(models.Model):
|
||||||
class Inquisition(models.Model):
|
class Inquisition(models.Model):
|
||||||
expected = models.BooleanField()
|
expected = models.BooleanField()
|
||||||
leader = models.ForeignKey(Actor)
|
leader = models.ForeignKey(Actor)
|
||||||
|
country = models.CharField(max_length=20)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.expected
|
return u"by %s from %s" % (self.leader, self.country)
|
||||||
|
|
||||||
|
class InquisitionAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('leader', 'country', 'expected')
|
||||||
|
|
||||||
class Sketch(models.Model):
|
class Sketch(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
inquisition = models.ForeignKey(Inquisition, limit_choices_to={'leader__name': 'Palin',
|
inquisition = models.ForeignKey(Inquisition, limit_choices_to={'leader__name': 'Palin',
|
||||||
'leader__age': 27,
|
'leader__age': 27,
|
||||||
|
'expected': False,
|
||||||
})
|
})
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
class SketchAdmin(admin.ModelAdmin):
|
||||||
|
raw_id_fields = ('inquisition',)
|
||||||
|
|
||||||
class Fabric(models.Model):
|
class Fabric(models.Model):
|
||||||
NG_CHOICES = (
|
NG_CHOICES = (
|
||||||
('Textured', (
|
('Textured', (
|
||||||
|
@ -663,8 +673,8 @@ admin.site.register(ModelWithStringPrimaryKey)
|
||||||
admin.site.register(Color)
|
admin.site.register(Color)
|
||||||
admin.site.register(Thing, ThingAdmin)
|
admin.site.register(Thing, ThingAdmin)
|
||||||
admin.site.register(Actor)
|
admin.site.register(Actor)
|
||||||
admin.site.register(Inquisition)
|
admin.site.register(Inquisition, InquisitionAdmin)
|
||||||
admin.site.register(Sketch)
|
admin.site.register(Sketch, SketchAdmin)
|
||||||
admin.site.register(Person, PersonAdmin)
|
admin.site.register(Person, PersonAdmin)
|
||||||
admin.site.register(Persona, PersonaAdmin)
|
admin.site.register(Persona, PersonaAdmin)
|
||||||
admin.site.register(Subscriber, SubscriberAdmin)
|
admin.site.register(Subscriber, SubscriberAdmin)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import urlparse
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
@ -34,7 +35,7 @@ from models import (Article, BarAccount, CustomArticle, EmptyModel,
|
||||||
Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast,
|
Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast,
|
||||||
Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit,
|
Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit,
|
||||||
Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee,
|
Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee,
|
||||||
Question, Answer)
|
Question, Answer, Inquisition, Actor)
|
||||||
|
|
||||||
|
|
||||||
class AdminViewBasicTest(TestCase):
|
class AdminViewBasicTest(TestCase):
|
||||||
|
@ -2350,6 +2351,39 @@ class ReadonlyTest(TestCase):
|
||||||
response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
|
response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class RawIdFieldsTest(TestCase):
|
||||||
|
fixtures = ['admin-views-users.xml']
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.client.login(username='super', password='secret')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.client.logout()
|
||||||
|
|
||||||
|
def test_limit_choices_to(self):
|
||||||
|
"""Regression test for 14880"""
|
||||||
|
# This includes tests integers, strings and booleans in the lookup query string
|
||||||
|
actor = Actor.objects.create(name="Palin", age=27)
|
||||||
|
inquisition1 = Inquisition.objects.create(expected=True,
|
||||||
|
leader=actor,
|
||||||
|
country="England")
|
||||||
|
inquisition2 = Inquisition.objects.create(expected=False,
|
||||||
|
leader=actor,
|
||||||
|
country="Spain")
|
||||||
|
response = self.client.get('/test_admin/admin/admin_views/sketch/add/')
|
||||||
|
# Find the link
|
||||||
|
m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_inquisition"', response.content)
|
||||||
|
self.assertTrue(m) # Got a match
|
||||||
|
popup_url = m.groups()[0].replace("&", "&")
|
||||||
|
|
||||||
|
# Handle relative links
|
||||||
|
popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url)
|
||||||
|
# Get the popup
|
||||||
|
response2 = self.client.get(popup_url)
|
||||||
|
self.assertContains(response2, "Spain")
|
||||||
|
self.assertNotContains(response2, "England")
|
||||||
|
|
||||||
class UserAdminTest(TestCase):
|
class UserAdminTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Tests user CRUD functionality.
|
Tests user CRUD functionality.
|
||||||
|
|
Loading…
Reference in New Issue