| 6 | |
| 7 | This is my {{{ElectricityReading}}} model and its parent {{{Reading}}} model (separated because we also have consumption readings for water and gas, which also derive from {{{Reading}}}): |
| 8 | |
| 9 | {{{#!python |
| 10 | from model_utils.models import TimeStampedModel |
| 11 | # Other imports here... |
| 12 | |
| 13 | class Reading(TimeStampedModel): |
| 14 | device = models.ForeignKey(Device) |
| 15 | datetime = models.DateTimeField() # Terrible property name, I know :) |
| 16 | manual = models.BooleanField(default=False) |
| 17 | inserted_by = models.ForeignKey(User) |
| 18 | |
| 19 | class Meta: |
| 20 | abstract = True |
| 21 | |
| 22 | class ElectricityReading(Reading): |
| 23 | vph1 = models.DecimalField(max_digits=18, decimal_places=3, null=True) |
| 24 | vph2 = models.DecimalField(max_digits=18, decimal_places=3, null=True) |
| 25 | vph3 = models.DecimalField(max_digits=18, decimal_places=3, null=True) |
| 26 | wh_imp = models.DecimalField(max_digits=18, decimal_places=3) |
| 27 | varh = models.DecimalField(max_digits=18, decimal_places=3, null=True) |
| 28 | pf = models.DecimalField(max_digits=18, decimal_places=3, null=True) |
| 29 | |
| 30 | price = models.ForeignKey(ElectricityPrice) |
| 31 | consumption = models.DecimalField(max_digits=18, decimal_places=3, |
| 32 | null=True, blank=True, default=None) |
| 33 | cost = models.DecimalField(max_digits=18, decimal_places=3, null=True, |
| 34 | blank=True, default=None) |
| 35 | }}} |