Created
May 24, 2010 20:01
-
-
Save djfroofy/412356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from djredis.models import DredisMixin | |
import djredis.fields | |
class Blog(models.Model, DredisMixin): # inherit from the mixin class | |
author = models.ForeignKey('Author') | |
title = models.CharField(max_length=200) | |
viewcount = djredis.fields.Counter() | |
# optionally add a unique keyspace for the instance - default is shown below | |
def redis_key(self): | |
return '%s:%s:%s' % (self._meta.app_label, self._meta.module_name, self.pk) | |
blog = Blog.objects.get(pk=1) | |
blog.viewcount.incr() | |
# or equivalently: | |
blog.viewcount += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment