Ticket #16128: 16128.2.patch

File 16128.2.patch, 2.3 KB (added by Aymeric Augustin, 13 years ago)
  • modeltests/proxy_models/tests.py

     
    1111from models import UserProxyProxy, Country, State, StateProxy, TrackerUser
    1212from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug
    1313from models import ProxyBug, ProxyImprovement
     14from models import AuthUser, AuthUserProxy, Profile, ProfileWithProxy
    1415
    1516class ProxyModelTests(TestCase):
    1617    def test_same_manager_queries(self):
     
    312313        management.call_command('loaddata', 'mypeople.json', verbosity=0, commit=False)
    313314        p = MyPerson.objects.get(pk=100)
    314315        self.assertEqual(p.name, 'Elvis Presley')
     316
     317    def test_delete_cascade_to_proxy_objects(self):
     318        """
     319        Test that delete() cascades to proxy objects. Regression for #16128.
     320        """
     321        # delete with a foreign key on a regular model
     322        joe = AuthUser.objects.create()
     323        joe_s_profile = Profile.objects.create(user=joe)
     324        self.assertEqual(Profile.objects.count(), 1)
     325        joe.delete()
     326        self.assertEqual(Profile.objects.count(), 0)
     327        # delete with a foreign key on a proxy model
     328        joe = AuthUserProxy.objects.create()
     329        joe_s_profile = ProfileWithProxy.objects.create(user=joe)
     330        self.assertEqual(ProfileWithProxy.objects.count(), 1)
     331        joe.delete()
     332        self.assertEqual(ProfileWithProxy.objects.count(), 0)
  • modeltests/proxy_models/models.py

     
    55providing a modified interface to the data from the base class.
    66"""
    77
     8from django.contrib.auth.models import User as AuthUser
    89from django.contrib.contenttypes.models import ContentType
    910from django.db import models
    1011
     
    161162
    162163class ProxyImprovement(Improvement):
    163164    class Meta:
    164         proxy = True
    165  No newline at end of file
     165        proxy = True
     166
     167
     168class AuthUserProxy(AuthUser):
     169    class Meta:
     170        proxy = True
     171
     172class Profile(models.Model):
     173    user = models.ForeignKey(AuthUser)
     174
     175class ProfileWithProxy(models.Model):
     176    user = models.ForeignKey(AuthUserProxy)
Back to Top