class Message models Model author models ForeignKey Profile class Post

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Message(models.Model):
author = models.ForeignKey(Profile)
....
class Post(Message):
....
def save(self):
if seld.pk = None;
self.author.set_posts_num()
super(Posts, self).save()
class Comment(Message):
....
def save(self):
if self.pk = None:
self.author.set_questions()
super(Comment, self).save()
class Profile(models.Model):
user = models.ForeignKey(User)
posts_num = models.IntegerField(default=0)
comments_num = models.IntegerField(default=0)
....
def set_posts_num(self):
self.posts_num += 1
self.save()
def set_comments_num(self):
self.comments_num += 1
self.save()