parent
5d00a5f490
commit
e97090ceb3
|
@ -1,9 +1,13 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
import caching.base
|
||||
|
||||
class UserProfile(models.Model):
|
||||
|
||||
class UserProfile(caching.base.CachingMixin, models.Model):
|
||||
user = models.ForeignKey(User, unique=True)
|
||||
is_pro = models.BooleanField(default=False)
|
||||
|
||||
objects = caching.base.CachingManager()
|
||||
|
||||
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -29,3 +29,4 @@ git+git://github.com/yoavaviram/python-amazon-simple-product-api.git
|
|||
git+https://github.com/toastdriven/django-haystack.git@master#egg=django-haystack
|
||||
hg+https://bitbucket.org/ubernostrum/django-registration#egg=django-registration
|
||||
git+https://github.com/toastdriven/django-tastypie.git#egg=django-tastypie
|
||||
git+git://github.com/jbalogh/django-cache-machine.git#egg=django-cache-machine
|
||||
|
|
|
@ -213,6 +213,9 @@ ABSOLUTE_URL_OVERRIDES = {
|
|||
AUTH_PROFILE_MODULE = 'accounts.UserProfile'
|
||||
|
||||
# Caching
|
||||
CACHE_BACKEND = 'caching.backends.memcached://localhost:11211'
|
||||
CACHE_PREFIX = 'snipt:'
|
||||
CACHE_COUNT_TIMEOUT = 60
|
||||
|
||||
# Search
|
||||
HAYSTACK_CONNECTIONS = {
|
||||
|
|
|
@ -15,10 +15,12 @@ from snipts.utils import slugify_uniquely
|
|||
|
||||
import datetime, md5, re
|
||||
|
||||
import caching.base
|
||||
|
||||
|
||||
site = Site.objects.all()[0]
|
||||
|
||||
class Snipt(models.Model):
|
||||
class Snipt(caching.base.CachingMixin, models.Model):
|
||||
"""An individual Snipt."""
|
||||
|
||||
user = models.ForeignKey(User, blank=True, null=True)
|
||||
|
@ -42,6 +44,8 @@ class Snipt(models.Model):
|
|||
modified = models.DateTimeField(auto_now=True, editable=False)
|
||||
publish_date = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
objects = caching.base.CachingManager()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
if not self.slug:
|
||||
|
@ -154,12 +158,14 @@ class Snipt(models.Model):
|
|||
else:
|
||||
return get_lexer_by_name(self.lexer).name
|
||||
|
||||
class Favorite(models.Model):
|
||||
class Favorite(caching.base.CachingMixin, models.Model):
|
||||
snipt = models.ForeignKey(Snipt)
|
||||
user = models.ForeignKey(User)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
modified = models.DateTimeField(auto_now=True, editable=False)
|
||||
|
||||
objects = caching.base.CachingManager()
|
||||
|
||||
def __unicode__(self):
|
||||
return u'{} favorited by {}'.format(self.snipt.title, self.user.username)
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
from django.db import models
|
||||
|
Loading…
Reference in New Issue