diff -r f53e259a7214 tests/regressiontests/admin_views/models.py
a
|
b
|
|
599 | 599 | list_display = ('datum', 'employee') |
600 | 600 | list_filter = ('employee',) |
601 | 601 | |
| 602 | class Publisher(models.Model): |
| 603 | name = models.CharField(max_length=20) |
| 604 | overseas = models.BooleanField() |
| 605 | |
| 606 | class PublishedBook(models.Model): |
| 607 | title = models.CharField(max_length=20) |
| 608 | local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False}) |
| 609 | |
| 610 | class PublishedBookAdmin(admin.ModelAdmin): |
| 611 | raw_id_fields = ['local_publisher',] |
| 612 | |
| 613 | class PublisherAdmin(admin.ModelAdmin): |
| 614 | list_display = ['name', 'overseas'] |
| 615 | |
602 | 616 | admin.site.register(Article, ArticleAdmin) |
603 | 617 | admin.site.register(CustomArticle, CustomArticleAdmin) |
604 | 618 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
|
647 | 661 | admin.site.register(Pizza, PizzaAdmin) |
648 | 662 | admin.site.register(Topping) |
649 | 663 | admin.site.register(Album, AlbumAdmin) |
| 664 | admin.site.register(PublishedBook, PublishedBookAdmin) |
| 665 | admin.site.register(Publisher, PublisherAdmin) |
diff -r f53e259a7214 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, WorkHour, Employee |
| 32 | Category, Post, Plot, FunkyTag, WorkHour, Employee, Publisher |
32 | 33 | |
33 | 34 | |
34 | 35 | class AdminViewBasicTest(TestCase): |
… |
… |
|
2154 | 2155 | response = self.client.get('/test_admin/admin/admin_views/pizza/add/') |
2155 | 2156 | self.assertEqual(response.status_code, 200) |
2156 | 2157 | |
| 2158 | class RawIdFieldsTest(TestCase): |
| 2159 | fixtures = ['admin-views-users.xml'] |
| 2160 | |
| 2161 | def setUp(self): |
| 2162 | self.client.login(username='super', password='secret') |
| 2163 | |
| 2164 | def tearDown(self): |
| 2165 | self.client.logout() |
| 2166 | |
| 2167 | def test_limit_choices_to(self): |
| 2168 | """Regression test for 14880""" |
| 2169 | Publisher(name='local-guy', overseas=False).save() |
| 2170 | Publisher(name='overseas-guy', overseas=True).save() |
| 2171 | response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/') |
| 2172 | # Find the link |
| 2173 | m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content) |
| 2174 | self.assertTrue(m) # Got a match |
| 2175 | popup_url = m.groups()[0].replace("&", "&") |
| 2176 | |
| 2177 | # Handle relative links |
| 2178 | popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url) |
| 2179 | # Get the popup |
| 2180 | response2 = self.client.get(popup_url) |
| 2181 | self.assertContains(response2, "local-guy") |
| 2182 | self.assertNotContains(response2, "overseas-guy") |
| 2183 | |
2157 | 2184 | class UserAdminTest(TestCase): |
2158 | 2185 | """ |
2159 | 2186 | Tests user CRUD functionality. |