| 1 | #
|
|---|
| 2 | # The code to generate the shell results.
|
|---|
| 3 | #
|
|---|
| 4 |
|
|---|
| 5 | from modeltests.model_inheritance.models import *
|
|---|
| 6 | Vehicle.objects.all().delete()
|
|---|
| 7 | Boat(name="dingy", has_sail=False).save()
|
|---|
| 8 | dingy_vehicle = Vehicle.objects.get(name="dingy")
|
|---|
| 9 | dingy_vehicle.car
|
|---|
| 10 | dingy_vehicle.boat
|
|---|
| 11 | dingy_vehicle.car
|
|---|
| 12 | dingy_vehicle.boat
|
|---|
| 13 | Car(name="my rolls", wheels=4).save()
|
|---|
| 14 | rolls_vehicle = Vehicle.objects.get(name="my rolls")
|
|---|
| 15 | rolls_vehicle.car
|
|---|
| 16 | rolls_vehicle.boat
|
|---|
| 17 | rolls_vehicle.car
|
|---|
| 18 | rolls_vehicle.boat
|
|---|
| 19 | amphibian = Amphibian()
|
|---|
| 20 | amphibian.name = "optimus prime"
|
|---|
| 21 | amphibian.has_sail = True
|
|---|
| 22 | amphibian.wheels = 23
|
|---|
| 23 | amphibian.is_a_robot_in_disguise = True
|
|---|
| 24 | amphibian.save()
|
|---|
| 25 | robot_vehicle = Vehicle.objects.get(name="optimus prime")
|
|---|
| 26 | robot_vehicle.car
|
|---|
| 27 | robot_vehicle.boat
|
|---|
| 28 | robot_vehicle.car
|
|---|
| 29 | robot_vehicle.boat
|
|---|
| 30 | robot_vehicle.car.amphibian
|
|---|
| 31 | robot_vehicle.boat.amphibian
|
|---|
| 32 |
|
|---|
| 33 | #
|
|---|
| 34 | # Shell results before the code was changed
|
|---|
| 35 | #
|
|---|
| 36 |
|
|---|
| 37 | >>> from modeltests.model_inheritance.models import *
|
|---|
| 38 | >>> Vehicle.objects.all().delete()
|
|---|
| 39 | >>> Boat(name="dingy", has_sail=False).save()
|
|---|
| 40 | >>> dingy_vehicle = Vehicle.objects.get(name="dingy")
|
|---|
| 41 | >>> dingy_vehicle.car
|
|---|
| 42 | Traceback (most recent call last):
|
|---|
| 43 | ...
|
|---|
| 44 | DoesNotExist: Car matching query does not exist.
|
|---|
| 45 | >>> dingy_vehicle.boat
|
|---|
| 46 | <Boat: A boat called dingy without a sail>
|
|---|
| 47 | >>> dingy_vehicle.car # should get error
|
|---|
| 48 | <Boat: A boat called dingy without a sail>
|
|---|
| 49 | >>> dingy_vehicle.boat
|
|---|
| 50 | <Boat: A boat called dingy without a sail>
|
|---|
| 51 | >>> Car(name="my rolls", wheels=4).save()
|
|---|
| 52 | >>> rolls_vehicle = Vehicle.objects.get(name="my rolls")
|
|---|
| 53 | >>> rolls_vehicle.car
|
|---|
| 54 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 55 | >>> rolls_vehicle.boat # should get error
|
|---|
| 56 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 57 | >>> rolls_vehicle.car
|
|---|
| 58 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 59 | >>> rolls_vehicle.boat # should get error
|
|---|
| 60 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 61 | >>> amphibian = Amphibian()
|
|---|
| 62 | >>> amphibian.name = "optimus prime"
|
|---|
| 63 | >>> amphibian.has_sail = True
|
|---|
| 64 | >>> amphibian.wheels = 23
|
|---|
| 65 | >>> amphibian.is_a_robot_in_disguise = True
|
|---|
| 66 | >>> amphibian.save()
|
|---|
| 67 | >>> robot_vehicle = Vehicle.objects.get(name="optimus prime")
|
|---|
| 68 | >>> robot_vehicle.car
|
|---|
| 69 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 70 | >>> robot_vehicle.boat # wrong object we want to see the boat part of optimus prime
|
|---|
| 71 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 72 | >>> robot_vehicle.car
|
|---|
| 73 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 74 | >>> robot_vehicle.boat # wrong object we want to see the boat part of optimus prime
|
|---|
| 75 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 76 | >>> robot_vehicle.car.amphibian
|
|---|
| 77 | <Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
|
|---|
| 78 | >>> robot_vehicle.boat.amphibian
|
|---|
| 79 | <Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
|
|---|
| 80 |
|
|---|
| 81 | #
|
|---|
| 82 | # Shell results after the code was changed
|
|---|
| 83 | #
|
|---|
| 84 |
|
|---|
| 85 | >>> from modeltests.model_inheritance.models import *
|
|---|
| 86 | >>> Vehicle.objects.all().delete()
|
|---|
| 87 | >>> Boat(name="dingy", has_sail=False).save()
|
|---|
| 88 | >>> dingy_vehicle = Vehicle.objects.get(name="dingy")
|
|---|
| 89 | >>> dingy_vehicle.car # the dingy is not a car
|
|---|
| 90 | Traceback (most recent call last):
|
|---|
| 91 | ...
|
|---|
| 92 | DoesNotExist: Car matching query does not exist.
|
|---|
| 93 | >>> dingy_vehicle.boat
|
|---|
| 94 | <Boat: A boat called dingy without a sail>
|
|---|
| 95 | >>> dingy_vehicle.car # the dingy is still not a car
|
|---|
| 96 | Traceback (most recent call last):
|
|---|
| 97 | ...
|
|---|
| 98 | DoesNotExist: Car matching query does not exist.
|
|---|
| 99 | >>> dingy_vehicle.boat
|
|---|
| 100 | <Boat: A boat called dingy without a sail>
|
|---|
| 101 | >>> Car(name="my rolls", wheels=4).save()
|
|---|
| 102 | >>> rolls_vehicle = Vehicle.objects.get(name="my rolls")
|
|---|
| 103 | >>> rolls_vehicle.car
|
|---|
| 104 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 105 | >>> rolls_vehicle.boat
|
|---|
| 106 | Traceback (most recent call last):
|
|---|
| 107 | ...
|
|---|
| 108 | DoesNotExist: Boat matching query does not exist.
|
|---|
| 109 | >>> rolls_vehicle.car
|
|---|
| 110 | <Car: A car called my rolls with 4 wheels>
|
|---|
| 111 | >>> rolls_vehicle.boat
|
|---|
| 112 | Traceback (most recent call last):
|
|---|
| 113 | ...
|
|---|
| 114 | DoesNotExist: Boat matching query does not exist.
|
|---|
| 115 | >>> amphibian = Amphibian()
|
|---|
| 116 | >>> amphibian.name = "optimus prime"
|
|---|
| 117 | >>> amphibian.has_sail = True
|
|---|
| 118 | >>> amphibian.wheels = 23
|
|---|
| 119 | >>> amphibian.is_a_robot_in_disguise = True
|
|---|
| 120 | >>> amphibian.save()
|
|---|
| 121 | >>> robot_vehicle = Vehicle.objects.get(name="optimus prime")
|
|---|
| 122 | >>> robot_vehicle.car
|
|---|
| 123 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 124 | >>> robot_vehicle.boat
|
|---|
| 125 | <Boat: A boat called optimus prime with a sail>
|
|---|
| 126 | >>> robot_vehicle.car
|
|---|
| 127 | <Car: A car called optimus prime with 23 wheels>
|
|---|
| 128 | >>> robot_vehicle.boat
|
|---|
| 129 | <Boat: A boat called optimus prime with a sail>
|
|---|
| 130 | >>> robot_vehicle.car.amphibian
|
|---|
| 131 | <Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
|
|---|
| 132 | >>> robot_vehicle.boat.amphibian
|
|---|
| 133 | <Amphibian: An ampibian which is 1) A car called optimus prime with 23 wheels and 2) A boat called optimus prime with a sail>
|
|---|