Ticket #7483: delete_related.diff
File delete_related.diff, 5.6 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/util.py
19 19 return # Avoid recursing too deep. 20 20 opts_seen = [] 21 21 for related in opts.get_all_related_objects(): 22 has_admin = related. __class__in admin_site._registry22 has_admin = related.model in admin_site._registry 23 23 if related.opts in opts_seen: 24 24 continue 25 25 opts_seen.append(related.opts) … … 68 68 if not user.has_perm(p): 69 69 perms_needed.add(related.opts.verbose_name) 70 70 for related in opts.get_all_related_many_to_many_objects(): 71 has_admin = related. __class__in admin_site._registry71 has_admin = related.model in admin_site._registry 72 72 if related.opts in opts_seen: 73 73 continue 74 74 opts_seen.append(related.opts) -
tests/regressiontests/admin_views/fixtures/admin-views-users.xml
70 70 <field to="auth.group" name="groups" rel="ManyToManyRel"></field> 71 71 <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field> 72 72 </object> 73 <object pk="1" model="admin_views.section"> 74 <field type="CharField" name="name">Test section</field> 75 </object> 73 76 <object pk="1" model="admin_views.article"> 74 77 <field type="TextField" name="content"><p>test content</p></field> 75 78 <field type="DateTimeField" name="date">2008-03-18 11:54:58</field> 79 <field to="admin_views.section" name="section" rel="ManyToOneRel">1</field> 76 80 </object> 77 81 </django-objects> 82 No newline at end of file -
tests/regressiontests/admin_views/tests.py
5 5 from django.contrib.admin.sites import LOGIN_FORM_KEY, _encode_post_data 6 6 7 7 # local test models 8 from models import Article, CustomArticle 8 from models import Article, CustomArticle, Section 9 9 10 10 def get_perm(Model, perm): 11 11 """Return the permission object, for the Model""" … … 40 40 delete_user = User.objects.get(username='deleteuser') 41 41 delete_user.user_permissions.add(get_perm(Article, 42 42 opts.get_delete_permission())) 43 44 delete_user.user_permissions.add(get_perm(Section, 45 Section._meta.get_delete_permission())) 43 46 44 47 # login POST dicts 45 48 self.super_login = {'post_data': _encode_post_data({}), … … 116 119 """Test add view restricts access and actually adds items.""" 117 120 118 121 add_dict = {'content': '<p>great article</p>', 119 'date_0': '2008-03-18', 'date_1': '10:54:39'} 122 'date_0': '2008-03-18', 'date_1': '10:54:39', 123 'section': 1} 120 124 121 125 # Change User should not have access to add articles 122 126 self.client.get('/test_admin/admin/') … … 158 162 """Change view should restrict access and allow users to edit items.""" 159 163 160 164 change_dict = {'content': '<p>edited article</p>', 161 'date_0': '2008-03-18', 'date_1': '10:54:39'} 165 'date_0': '2008-03-18', 'date_1': '10:54:39', 166 'section': 1} 162 167 163 168 # add user shoud not be able to view the list of article or change any of them 164 169 self.client.get('/test_admin/admin/') … … 270 275 # Delete user can delete 271 276 self.client.get('/test_admin/admin/') 272 277 self.client.post('/test_admin/admin/', self.deleteuser_login) 273 request = self.client.get('/test_admin/admin/admin_views/article/1/delete/') 274 self.failUnlessEqual(request.status_code, 200) 278 response = self.client.get('/test_admin/admin/admin_views/section/1/delete/') 279 # test response contains link to related Article 280 self.assertContains(response, "admin_views/article/1/") 281 282 response = self.client.get('/test_admin/admin/admin_views/article/1/delete/') 283 self.failUnlessEqual(response.status_code, 200) 275 284 post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict) 276 285 # TODO: http://code.djangoproject.com/ticket/6819 or the next line fails 277 286 self.assertRedirects(post, '/test_admin/admin/') -
tests/regressiontests/admin_views/models.py
1 1 from django.db import models 2 2 from django.contrib import admin 3 3 4 class Section(models.Model): 5 """ 6 A simple section that links to articles, to test linking to related items in 7 admin views. 8 """ 9 name = models.CharField(max_length=100) 10 4 11 class Article(models.Model): 5 12 """ 6 13 A simple article to test admin views. Test backwards compabilty. 7 14 """ 8 15 content = models.TextField() 9 16 date = models.DateTimeField() 17 section = models.ForeignKey(Section) 10 18 11 19 class ArticleAdmin(admin.ModelAdmin): 12 20 list_display = ('content', 'date') … … 39 47 40 48 admin.site.register(Article, ArticleAdmin) 41 49 admin.site.register(CustomArticle, CustomArticleAdmin) 50 admin.site.register(Section)