Ticket #7483: delete_related.diff

File delete_related.diff, 5.6 KB (added by Daniel Roseman <daniel@…>, 16 years ago)

Patch and updated tests/fixtures

  • django/contrib/admin/util.py

     
    1919        return # Avoid recursing too deep.
    2020    opts_seen = []
    2121    for related in opts.get_all_related_objects():
    22         has_admin = related.__class__ in admin_site._registry
     22        has_admin = related.model in admin_site._registry
    2323        if related.opts in opts_seen:
    2424            continue
    2525        opts_seen.append(related.opts)
     
    6868                if not user.has_perm(p):
    6969                    perms_needed.add(related.opts.verbose_name)
    7070    for related in opts.get_all_related_many_to_many_objects():
    71         has_admin = related.__class__ in admin_site._registry
     71        has_admin = related.model in admin_site._registry
    7272        if related.opts in opts_seen:
    7373            continue
    7474        opts_seen.append(related.opts)
  • tests/regressiontests/admin_views/fixtures/admin-views-users.xml

     
    7070        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
    7171        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
    7272    </object>
     73    <object pk="1" model="admin_views.section">
     74        <field type="CharField" name="name">Test section</field>
     75    </object>
    7376    <object pk="1" model="admin_views.article">
    7477        <field type="TextField" name="content">&lt;p&gt;test content&lt;/p&gt;</field>
    7578        <field type="DateTimeField" name="date">2008-03-18 11:54:58</field>
     79        <field to="admin_views.section" name="section" rel="ManyToOneRel">1</field>
    7680    </object>
    7781</django-objects>
     82 No newline at end of file
  • tests/regressiontests/admin_views/tests.py

     
    55from django.contrib.admin.sites import LOGIN_FORM_KEY, _encode_post_data
    66
    77# local test models
    8 from models import Article, CustomArticle
     8from models import Article, CustomArticle, Section
    99
    1010def get_perm(Model, perm):
    1111    """Return the permission object, for the Model"""
     
    4040        delete_user = User.objects.get(username='deleteuser')
    4141        delete_user.user_permissions.add(get_perm(Article,
    4242            opts.get_delete_permission()))
     43
     44        delete_user.user_permissions.add(get_perm(Section,
     45            Section._meta.get_delete_permission()))
    4346       
    4447        # login POST dicts
    4548        self.super_login = {'post_data': _encode_post_data({}),
     
    116119        """Test add view restricts access and actually adds items."""
    117120       
    118121        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}
    120124       
    121125        # Change User should not have access to add articles
    122126        self.client.get('/test_admin/admin/')
     
    158162        """Change view should restrict access and allow users to edit items."""
    159163       
    160164        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}
    162167       
    163168        # add user shoud not be able to view the list of article or change any of them
    164169        self.client.get('/test_admin/admin/')
     
    270275        # Delete user can delete
    271276        self.client.get('/test_admin/admin/')
    272277        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)
    275284        post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict)
    276285        # TODO: http://code.djangoproject.com/ticket/6819 or the next line fails
    277286        self.assertRedirects(post, '/test_admin/admin/')
  • tests/regressiontests/admin_views/models.py

     
    11from django.db import models
    22from django.contrib import admin
    33
     4class 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
    411class Article(models.Model):
    512    """
    613    A simple article to test admin views. Test backwards compabilty.
    714    """
    815    content = models.TextField()
    916    date = models.DateTimeField()
     17    section = models.ForeignKey(Section)
    1018
    1119class ArticleAdmin(admin.ModelAdmin):
    1220    list_display = ('content', 'date')
     
    3947       
    4048admin.site.register(Article, ArticleAdmin)
    4149admin.site.register(CustomArticle, CustomArticleAdmin)
     50admin.site.register(Section)
Back to Top