diff --git a/article/__pycache__/models.cpython-36.pyc b/article/__pycache__/models.cpython-36.pyc index dd15828..8791d41 100644 Binary files a/article/__pycache__/models.cpython-36.pyc and b/article/__pycache__/models.cpython-36.pyc differ diff --git a/article/migrations/0015_article_comment_count.py b/article/migrations/0015_article_comment_count.py new file mode 100644 index 0000000..5b3ed46 --- /dev/null +++ b/article/migrations/0015_article_comment_count.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-03-01 03:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0014_auto_20180228_1552'), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='comment_count', + field=models.IntegerField(default=0), + ), + ] diff --git a/article/migrations/0016_comment_invalid.py b/article/migrations/0016_comment_invalid.py new file mode 100644 index 0000000..d7e5115 --- /dev/null +++ b/article/migrations/0016_comment_invalid.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.2 on 2018-03-01 06:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('article', '0015_article_comment_count'), + ] + + operations = [ + migrations.AddField( + model_name='comment', + name='invalid', + field=models.CharField(choices=[('Y', '是'), ('N', '否')], default='N', max_length=64), + ), + ] diff --git a/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc b/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc new file mode 100644 index 0000000..77c2ba5 Binary files /dev/null and b/article/migrations/__pycache__/0015_article_comment_count.cpython-36.pyc differ diff --git a/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc b/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc new file mode 100644 index 0000000..420bdf4 Binary files /dev/null and b/article/migrations/__pycache__/0016_comment_invalid.cpython-36.pyc differ diff --git a/article/models.py b/article/models.py index ed98dbb..95acb89 100644 --- a/article/models.py +++ b/article/models.py @@ -4,6 +4,8 @@ from django.contrib.auth.models import User from django.forms import * from userpage.models import * +from django.db.models.signals import post_save +from django.dispatch import receiver #from django.conf import settings #from tagging.fields import TagField #from tagging.models import Tag @@ -35,7 +37,8 @@ class Article(models.Model): tag = models.CharField(max_length=128, blank=True, null=True) visible = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='N') readtime = models.IntegerField(default=0) - #comment_count = models.IntegerField(default=0) + comment_count = models.IntegerField(default=0) + #update_time = models.DateTimeField(auto_now=True,blank=True,null=True) #def set_tags(self, tags): # Tag.objects.update_tags(self, tags) @@ -48,6 +51,7 @@ class Meta: db_table ="article" ordering = ['-publish_time'] + class ArticleForm(ModelForm): class Meta: model = Article @@ -76,6 +80,7 @@ class Comment(models.Model): user = models.ForeignKey(Profile,on_delete=models.CASCADE,default=0) comment_time = models.DateTimeField(auto_now_add=True,editable=False) comment = HTMLField() + invalid = models.CharField(choices=(('Y','是'),('N','否')),max_length=64,default='N') ip = models.GenericIPAddressField(blank=True,null=True,default='0.0.0.0') clickcount = models.IntegerField(default=0) refer = models.CharField(max_length=5096,default='none') @@ -91,7 +96,15 @@ class Meta: class CommentForm(ModelForm): class Meta: model = Comment - fields = ('article','user','comment','ip') + fields = ('article','user','comment','ip','invalid') widgets = { 'comment':TinyMCE(attrs={'cols':'100%','rows':10}), } + + +@receiver(post_save, sender=Comment) +def comment_count(sender, created, instance, **kwargs): + if created: + art = Article.objects.get(pk=instance.article.id) + art.comment_count += 1 + art.save() diff --git a/article/templates/article/detail.html b/article/templates/article/detail.html index 74e50f3..890bbfb 100644 --- a/article/templates/article/detail.html +++ b/article/templates/article/detail.html @@ -54,16 +54,16 @@
评论
- + {% for i in comments %} -
{% if art %}{{art.title}}{% endif %}
+ {% ifequal i.invalid 'Y' %} +“此评论违规”
+ {% else %} {{i.comment|safe|escape}} + {% endifequal %} +{% if title %}{{title}}{% endif %}
{{i.section}} + {{i.readtime}} + {{i.tag}} 阅读全文 diff --git a/userpage/__pycache__/models.cpython-36.pyc b/userpage/__pycache__/models.cpython-36.pyc index 02de966..9b1e159 100644 Binary files a/userpage/__pycache__/models.cpython-36.pyc and b/userpage/__pycache__/models.cpython-36.pyc differ diff --git a/userpage/__pycache__/views.cpython-36.pyc b/userpage/__pycache__/views.cpython-36.pyc index 2b42b88..f9547bc 100644 Binary files a/userpage/__pycache__/views.cpython-36.pyc and b/userpage/__pycache__/views.cpython-36.pyc differ diff --git a/userpage/models.py b/userpage/models.py index b28ddfb..7f0bd69 100644 --- a/userpage/models.py +++ b/userpage/models.py @@ -30,11 +30,12 @@ def save_user_profile(sender, instance, **kwargs): class UserForm(ModelForm): class Meta: model = User - fields = ('first_name', 'last_name', 'email') + fields = ('username','first_name', 'last_name', 'email') widgets = { - 'email':TextInput(attrs={'class':'form-control','placeholder':"E-mail"}), - 'first_name':TextInput(attrs={'class':'form-control','placeholder':"First Name"}), - 'last_name':TextInput(attrs={'class':'form-control','placeholder':"Last Name"}), + 'username':TextInput(attrs={'class':'form-control','placeholder':"Username"}), + 'email':TextInput(attrs={'class':'form-control','placeholder':"E-mail"}), + 'first_name':TextInput(attrs={'class':'form-control','placeholder':"First Name"}), + 'last_name':TextInput(attrs={'class':'form-control','placeholder':"Last Name"}), } class ProfileForm(ModelForm): diff --git a/userpage/templates/userpage/profile.html b/userpage/templates/userpage/profile.html index 83aee1c..5691900 100644 --- a/userpage/templates/userpage/profile.html +++ b/userpage/templates/userpage/profile.html @@ -1,7 +1,17 @@ {% extends "base.html"%} - +{% load upto %} {% block header %}