return self.can_delete_comment(post)
return (self == post.author and (post.__class__.__name__ == "Answer" or
- not post.answers.exclude(author=self).count()))
+ not post.answers.exclude(author__id=self.id).count()))
@true_if_is_super_or_staff
def can_upload_files(self):
class Meta:
app_label = 'forum'
-class UserProperty(models.Model):
+class UserProperty(BaseModel):
user = models.ForeignKey(User, related_name='properties')
key = models.CharField(max_length=16)
value = PickledObjectField()
app_label = 'forum'
unique_together = ('user', 'key')
+ def cache_key(self):
+ return self._generate_cache_key("%s:%s" % (self.user.id, self.key))
+
+ @classmethod
+ def infer_cache_key(cls, querydict):
+ if 'user' in querydict and 'key' in querydict:
+ return cls._generate_cache_key("%s:%s" % (querydict['user'].id, querydict['key']))
+
+ return None
+
class UserPropertyDict(object):
def __init__(self, user):
self.__dict__['_user'] = user
if current:
current.value = value
self.__dict__[name] = value
- current.save()
+ current.save(full_save=True)
else:
user = self.__dict__['_user']
prop = UserProperty(user=user, value=value, key=name)