Ticket #16176: patch_and_test.diff

File patch_and_test.diff, 2.8 KB (added by Thomas_Moronez, 11 years ago)

Sets attributes with property decorators to the class with a None value

  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 5f05865..64af5c6 100644
    a b class ModelBase(type):  
    252252                cls.add_to_class(mgr_name, new_manager)
    253253
    254254    def add_to_class(cls, name, value):
    255         if hasattr(value, 'contribute_to_class'):
     255        if isinstance(value, property):
     256             setattr(cls, name, None)
     257        elif hasattr(value, 'contribute_to_class'):
    256258            value.contribute_to_class(cls, name)
    257259        else:
    258260            setattr(cls, name, value)
  • tests/regressiontests/model_inheritance_regress/models.py

    diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
    index 811c817..bf4351d 100644
    a b class User(models.Model):  
    182182class Profile(User):
    183183    profile_id = models.AutoField(primary_key=True)
    184184    extra = models.CharField(max_length=30, blank=True)
     185       
     186       
     187class SomeTestModel(models.Model):
     188    some_field = models.CharField(max_length=100)
     189
     190    class Meta:
     191        abstract = True
     192               
     193    @property
     194    def other_field(self):
     195        return "[OTHER] %s" % self.some_field
     196
     197class OtherModel(SomeTestModel):
     198    other_field = models.CharField(max_length=100)
     199    other_field2 = models.CharField(max_length=100)
  • tests/regressiontests/model_inheritance_regress/tests.py

    diff --git a/tests/regressiontests/model_inheritance_regress/tests.py b/tests/regressiontests/model_inheritance_regress/tests.py
    index 8f741bb..e9cf2d9 100644
    a b from .models import (Place, Restaurant, ItalianRestaurant, ParkingLot,  
    1313    ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
    1414    SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
    1515    Person, BirthdayParty, BachelorParty, MessyBachelorParty,
    16     InternalCertificationAudit, BusStation, TrainStation, User, Profile)
     16    InternalCertificationAudit, BusStation, TrainStation, User, Profile, SomeTestModel, OtherModel)
    1717
    1818
    1919class ModelInheritanceTest(TestCase):
     20
     21    def test_16176(self):
     22        # Regression for #16176
     23        test1 = SomeTestModel(some_field = "hi")
     24        test2 = OtherModel(other_field = "hi")
     25        test3 = OtherModel(other_field2 = "hi")
     26               
    2027    def test_model_inheritance(self):
    2128        # Regression for #7350, #7202
    2229        # Check that when you create a Parent object with a specific reference
    class ModelInheritanceTest(TestCase):  
    422429        form = ProfileForm({'username': "user_with_profile", 'extra': "hello"},
    423430                           instance=p)
    424431        self.assertTrue(form.is_valid())
     432               
     433   
Back to Top