diff -r 60a71b474c6f tests/regressiontests/admin_views/models.py
a
|
b
|
|
626 | 626 | list_display = ('datum', 'employee') |
627 | 627 | list_filter = ('employee',) |
628 | 628 | |
| 629 | class Publisher(models.Model): |
| 630 | name = models.CharField(max_length=20) |
| 631 | overseas = models.BooleanField() |
| 632 | |
| 633 | class PublishedBook(models.Model): |
| 634 | title = models.CharField(max_length=20) |
| 635 | local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False}) |
| 636 | |
| 637 | class PublishedBookAdmin(admin.ModelAdmin): |
| 638 | raw_id_fields = ['local_publisher',] |
| 639 | |
| 640 | class PublisherAdmin(admin.ModelAdmin): |
| 641 | list_display = ['name', 'overseas'] |
| 642 | |
629 | 643 | admin.site.register(Article, ArticleAdmin) |
630 | 644 | admin.site.register(CustomArticle, CustomArticleAdmin) |
631 | 645 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
|
674 | 688 | admin.site.register(Pizza, PizzaAdmin) |
675 | 689 | admin.site.register(Topping) |
676 | 690 | admin.site.register(Album, AlbumAdmin) |
| 691 | admin.site.register(PublishedBook, PublishedBookAdmin) |
| 692 | admin.site.register(Publisher, PublisherAdmin) |
diff -r 60a71b474c6f 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 import mail |
… |
… |
|
33 | 34 | FooAccount, Gallery, ModelWithStringPrimaryKey, \ |
34 | 35 | Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ |
35 | 36 | Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ |
36 | | Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee |
| 37 | Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, \ |
| 38 | Publisher |
37 | 39 | |
38 | 40 | |
39 | 41 | class AdminViewBasicTest(TestCase): |
… |
… |
|
2307 | 2309 | response = self.client.get('/test_admin/admin/admin_views/pizza/add/') |
2308 | 2310 | self.assertEqual(response.status_code, 200) |
2309 | 2311 | |
| 2312 | class RawIdFieldsTest(TestCase): |
| 2313 | fixtures = ['admin-views-users.xml'] |
| 2314 | |
| 2315 | def setUp(self): |
| 2316 | self.client.login(username='super', password='secret') |
| 2317 | |
| 2318 | def tearDown(self): |
| 2319 | self.client.logout() |
| 2320 | |
| 2321 | def test_limit_choices_to(self): |
| 2322 | """Regression test for 14880""" |
| 2323 | Publisher(name='local-guy', overseas=False).save() |
| 2324 | Publisher(name='overseas-guy', overseas=True).save() |
| 2325 | response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/') |
| 2326 | # Find the link |
| 2327 | m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content) |
| 2328 | self.assertTrue(m) # Got a match |
| 2329 | popup_url = m.groups()[0].replace("&", "&") |
| 2330 | |
| 2331 | # Handle relative links |
| 2332 | popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url) |
| 2333 | # Get the popup |
| 2334 | response2 = self.client.get(popup_url) |
| 2335 | self.assertContains(response2, "local-guy") |
| 2336 | self.assertNotContains(response2, "overseas-guy") |
| 2337 | |
2310 | 2338 | class UserAdminTest(TestCase): |
2311 | 2339 | """ |
2312 | 2340 | Tests user CRUD functionality. |