diff -r 82628dcefb60 tests/regressiontests/admin_views/models.py
a
|
b
|
|
587 | 587 | class AlbumAdmin(admin.ModelAdmin): |
588 | 588 | list_filter = ['title'] |
589 | 589 | |
| 590 | class Publisher(models.Model): |
| 591 | name = models.CharField(max_length=20) |
| 592 | overseas = models.BooleanField() |
| 593 | |
| 594 | class PublishedBook(models.Model): |
| 595 | title = models.CharField(max_length=20) |
| 596 | local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False}) |
| 597 | |
| 598 | class PublishedBookAdmin(admin.ModelAdmin): |
| 599 | raw_id_fields = ['local_publisher',] |
| 600 | |
| 601 | class PublisherAdmin(admin.ModelAdmin): |
| 602 | list_display = ['name', 'overseas'] |
| 603 | |
590 | 604 | admin.site.register(Article, ArticleAdmin) |
591 | 605 | admin.site.register(CustomArticle, CustomArticleAdmin) |
592 | 606 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
|
634 | 648 | admin.site.register(Pizza, PizzaAdmin) |
635 | 649 | admin.site.register(Topping) |
636 | 650 | admin.site.register(Album, AlbumAdmin) |
| 651 | admin.site.register(PublishedBook, PublishedBookAdmin) |
| 652 | admin.site.register(Publisher, PublisherAdmin) |
diff -r 82628dcefb60 tests/regressiontests/admin_views/tests.py
a
|
b
|
|
2 | 2 | |
3 | 3 | import re |
4 | 4 | import datetime |
| 5 | import urlparse |
5 | 6 | |
6 | 7 | from django.conf import settings |
7 | 8 | from django.core.exceptions import SuspiciousOperation |
… |
… |
|
28 | 29 | FooAccount, Gallery, ModelWithStringPrimaryKey, \ |
29 | 30 | Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ |
30 | 31 | Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ |
31 | | Category, Post, Plot, FunkyTag |
| 32 | Category, Post, Plot, FunkyTag, Publisher |
32 | 33 | |
33 | 34 | |
34 | 35 | class AdminViewBasicTest(TestCase): |
… |
… |
|
2139 | 2140 | response = self.client.get('/test_admin/admin/admin_views/pizza/add/') |
2140 | 2141 | self.assertEqual(response.status_code, 200) |
2141 | 2142 | |
| 2143 | class RawIdFieldsTest(TestCase): |
| 2144 | fixtures = ['admin-views-users.xml'] |
| 2145 | |
| 2146 | def setUp(self): |
| 2147 | self.client.login(username='super', password='secret') |
| 2148 | |
| 2149 | def tearDown(self): |
| 2150 | self.client.logout() |
| 2151 | |
| 2152 | def test_limit_choices_to(self): |
| 2153 | """Regression test for 14880""" |
| 2154 | Publisher(name='local-guy', overseas=False).save() |
| 2155 | Publisher(name='overseas-guy', overseas=True).save() |
| 2156 | response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/') |
| 2157 | # Find the link |
| 2158 | m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content) |
| 2159 | self.assertTrue(m) # Got a match |
| 2160 | popup_url = m.groups()[0].replace("&", "&") |
| 2161 | |
| 2162 | # Handle relative links |
| 2163 | popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url) |
| 2164 | # Get the popup |
| 2165 | response2 = self.client.get(popup_url) |
| 2166 | self.assertContains(response2, "local-guy") |
| 2167 | self.assertNotContains(response2, "overseas-guy") |
| 2168 | |
2142 | 2169 | class UserAdminTest(TestCase): |
2143 | 2170 | """ |
2144 | 2171 | Tests user CRUD functionality. |