Ticket #10808: model_inheritance.py.diff

File model_inheritance.py.diff, 1.2 KB (added by jianhuang, 6 years ago)

added a test of this patch--very simplified example along the lines mikemintz had

  • models.py

     
    116116    def __unicode__(self):
    117117        return u"%s the parking lot" % self.name
    118118
     119#
     120# Diamond inheritance test
     121#
     122class FoodPlace(models.Model):
     123    name = models.CharField(max_length=255)
     124
     125class Bar(FoodPlace):
     126    pass
     127
     128class Pizzeria(FoodPlace):
     129    pass
     130
     131class PizzeriaBar(Bar, Pizzeria):
     132    pizza_bar_specific_field = models.CharField(max_length = 255)
     133
    119134__test__ = {'API_TESTS':"""
    120135# The Student and Worker models both have 'name' and 'age' fields on them and
    121136# inherit the __unicode__() method, just as with normal Python subclassing.
     
    3103253
    311326>>> settings.DEBUG = False
    312327
     328# Test of diamond inheritance __init__. If B and C inherit from A, and D inherits from B and C, we should be able to use __init__ for D to properly set all the fields, regardless of the redundant copies of A's fields that D inherits from B and C.
     329
     330>>> p = PizzeriaBar(name="Mike's", pizza_bar_specific_field="Doodle")
     331>>> p.name == "Mike's"
     332True
     333>>> p.pizza_bar_specific_field == "Doodle"
     334True
    313335"""}
Back to Top