Changes between Initial Version and Version 1 of Ticket #29656, comment 6


Ignore:
Timestamp:
Aug 10, 2018, 12:32:20 PM (6 years ago)
Author:
James Addison

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29656, comment 6

    initial v1  
    1111        super(RangeTest, self).save(*args, **kwargs)
    1212}}}
     13
     14''Edit: I realize I could have made the code simpler (see below), but that sample code is from my project where I have several range fields on my model so I loop through a list of field names to test for `None`. For clarity, the workaround is as simple as:''
     15{{{
     16class RangeTest(models.Model):
     17    ...
     18    def save(self, *args, **kwargs):
     19        if self.age_range == None:
     20            self.age_range = self._meta.get_field('age_range').range_type()
     21
     22        super(RangeTest, self).save(*args, **kwargs)
     23
     24}}}
     25''Apologies for adding confusion.''
Back to Top