Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to compare two integer fields in a model method in django?

$
0
0

I want to compare two integer fields inside a method in a django model.The two fields are not correctly getting compared and it is throwing an errorfor example:

    total_slots = models.IntegerField(default=0, help_text="Total number of vehicle slots available for allocation.")    allocated_slots = models.IntegerField(default=0,                                          validators=[                                              MaxValueValidator(total_slots),                                              MinValueValidator(0)                                          ], )    def available_slots_left(self):    if self.allocated_slots < self.total_slots:        return True    return False

I tried to just simply do this:

    def available_slots_left(self):    if self.allocated_slots < self.total_slots:        return True    return False

but it didn't work and it returned this error:

TypeError: '<=' not supported between instances of 'IntegerField' and 'int'

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>