[–] boohoofoodoo 12y ago ↗ Not really the same but I typically just do something like this to prevent magic numbers sprinkled all over my consuming code...<code>class Section(TransformerCommon): """ working model """ TEMPERATURE_COLD = 20 NONE = 0 END = 1 BOTH = 2 END_INSULATION_LOC_CHOICES = ( (NONE, "None"), (END, "End"), (BOTH, "Both"), ) ... end_ins_location = models.IntegerField( choices=END_INSULATION_LOC_CHOICES, verbose_name="End Insulation Location") ... try: if self.end_ins_location == Section.NONE: ... elif self.end_ins_location == Section.END: ... elif self.end_ins_location == Section.BOTH: ... else: ...</code>
1 comment
[ 5.6 ms ] story [ 15.1 ms ] thread<code>
class Section(TransformerCommon): """ working model """ TEMPERATURE_COLD = 20
... end_ins_location = models.IntegerField( choices=END_INSULATION_LOC_CHOICES, verbose_name="End Insulation Location") ... try: if self.end_ins_location == Section.NONE: ... elif self.end_ins_location == Section.END: ... elif self.end_ins_location == Section.BOTH: ... else: ...</code>