diff -r 07edcd36e455 tests/regressiontests/admin_views/models.py
a
|
b
|
|
584 | 584 | owner = models.ForeignKey(User) |
585 | 585 | title = models.CharField(max_length=30) |
586 | 586 | |
| 587 | class Publisher(models.Model): |
| 588 | name = models.CharField(max_length=20) |
| 589 | overseas = models.BooleanField() |
| 590 | |
| 591 | class PublishedBook(models.Model): |
| 592 | title = models.CharField(max_length=20) |
| 593 | local_publisher = models.ForeignKey(Publisher, limit_choices_to={'overseas': False}) |
| 594 | |
| 595 | class PublishedBookAdmin(admin.ModelAdmin): |
| 596 | raw_id_fields = ['local_publisher',] |
| 597 | |
| 598 | class PublisherAdmin(admin.ModelAdmin): |
| 599 | list_display = ['name', 'overseas'] |
| 600 | |
587 | 601 | admin.site.register(Article, ArticleAdmin) |
588 | 602 | admin.site.register(CustomArticle, CustomArticleAdmin) |
589 | 603 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
|
631 | 645 | admin.site.register(Pizza, PizzaAdmin) |
632 | 646 | admin.site.register(Topping) |
633 | 647 | admin.site.register(Album) |
| 648 | admin.site.register(PublishedBook, PublishedBookAdmin) |
| 649 | admin.site.register(Publisher, PublisherAdmin) |
diff -r 07edcd36e455 tests/regressiontests/admin_views/tests.py
a
|
b
|
|
2 | 2 | |
3 | 3 | import re |
4 | 4 | import datetime |
| 5 | import urlparse |
5 | 6 | from django.conf import settings |
6 | 7 | from django.core.files import temp as tempfile |
7 | 8 | from django.contrib.auth import admin # Register auth models with the admin. |
… |
… |
|
24 | 25 | FooAccount, Gallery, ModelWithStringPrimaryKey, \ |
25 | 26 | Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \ |
26 | 27 | Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \ |
27 | | Category, Post, Plot, FunkyTag |
| 28 | Category, Post, Plot, FunkyTag, Publisher |
28 | 29 | |
29 | 30 | |
30 | 31 | class AdminViewBasicTest(TestCase): |
… |
… |
|
2128 | 2129 | response = self.client.get('/test_admin/admin/admin_views/pizza/add/') |
2129 | 2130 | self.assertEqual(response.status_code, 200) |
2130 | 2131 | |
| 2132 | class RawIdFieldsTest(TestCase): |
| 2133 | fixtures = ['admin-views-users.xml'] |
| 2134 | |
| 2135 | def setUp(self): |
| 2136 | self.client.login(username='super', password='secret') |
| 2137 | |
| 2138 | def tearDown(self): |
| 2139 | self.client.logout() |
| 2140 | |
| 2141 | def test_limit_choices_to(self): |
| 2142 | """Regression test for 14880""" |
| 2143 | Publisher(name='local-guy', overseas=False).save() |
| 2144 | Publisher(name='overseas-guy', overseas=True).save() |
| 2145 | response = self.client.get('/test_admin/admin/admin_views/publishedbook/add/') |
| 2146 | # Find the link |
| 2147 | m = re.search(r'<a href="([^"]*)"[^>]* id="lookup_id_local_publisher"', response.content) |
| 2148 | self.assertTrue(m) # Got a match |
| 2149 | popup_url = m.groups()[0].replace("&", "&") |
| 2150 | |
| 2151 | # Handle relative links |
| 2152 | popup_url = urlparse.urljoin(response.request['PATH_INFO'], popup_url) |
| 2153 | # Get the popup |
| 2154 | response2 = self.client.get(popup_url) |
| 2155 | self.assertContains(response2, "local-guy") |
| 2156 | self.assertNotContains(response2, "overseas-guy") |
| 2157 | |
2131 | 2158 | class UserAdminTest(TestCase): |
2132 | 2159 | """ |
2133 | 2160 | Tests user CRUD functionality. |