class ActiveTagManager(CachedManager):
use_for_related_fields = True
- def get_query_set(self):
- return super(ActiveTagManager, self).get_query_set().exclude(used_count__lt=1)
+ def get_queryset(self):
+ return super(ActiveTagManager, self).get_queryset().exclude(used_count__lt=1)
class Tag(BaseModel):
name = models.CharField(max_length=255, unique=True)
return force_unicode(self.name)
def add_to_usage_count(self, value):
- if int(self.used_count + value) < 0:
+ if self.used_count + value < 0:
self.used_count = 0
else:
- self.used_count += value
-
- self.save()
+ self.used_count = models.F('used_count') + value
def cache_key(self):
return self._generate_cache_key(Tag.safe_cache_name(self.name))