diff --git a/forum/forms.py b/forum/forms.py index ee108c8..5f8ff51 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -1,6 +1,6 @@ from django import forms from django.utils.translation import ugettext_lazy as _ -from .models import Forum +from .models import Forum, PostAnswer class ForumForm(forms.ModelForm): @@ -17,4 +17,16 @@ class ForumForm(forms.ModelForm): } widgets = { 'description': forms.Textarea(attrs={'cols': 80, 'rows': 5}), + } + +class PostAnswerForm(forms.ModelForm): + + class Meta: + model = PostAnswer + fields = ('message', ) + labels = { + 'message': _('Message') + } + widgets = { + 'message': forms.Textarea(attrs={'cols': 80, 'rows': 3}), } \ No newline at end of file diff --git a/forum/migrations/0004_auto_20160928_1558.py b/forum/migrations/0004_auto_20160928_1558.py new file mode 100644 index 0000000..8b01d64 --- /dev/null +++ b/forum/migrations/0004_auto_20160928_1558.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-09-28 18:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('forum', '0003_forum_create_date'), + ] + + operations = [ + migrations.AddField( + model_name='forum', + name='modification_date', + field=models.DateTimeField(auto_now=True, verbose_name='Modification Date'), + ), + migrations.AddField( + model_name='post', + name='modification_date', + field=models.DateTimeField(auto_now=True, verbose_name='Modification Date'), + ), + migrations.AddField( + model_name='postanswer', + name='modification_date', + field=models.DateTimeField(auto_now=True, verbose_name='Modification Date'), + ), + ] diff --git a/forum/models.py b/forum/models.py index 092fc35..fa9f4d0 100644 --- a/forum/models.py +++ b/forum/models.py @@ -12,6 +12,7 @@ It works like a 'topic' of forum, which users can post to it and answer posts of """ class Forum(Activity): description = models.TextField(_('Description'), blank = True) + modification_date = models.DateTimeField(_('Modification Date'), auto_now = True) create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) class Meta: @@ -28,6 +29,7 @@ It represents a post made in a forum (topic) class Post(models.Model): user = models.ForeignKey(User, verbose_name = _('Autor')) message = models.TextField(_('Post message'), blank = False) + modification_date = models.DateTimeField(_('Modification Date'), auto_now = True) post_date = models.DateTimeField(_('Post Date'), auto_now_add = True) forum = models.ForeignKey(Forum, verbose_name = _('Forum')) @@ -46,6 +48,7 @@ class PostAnswer(models.Model): user = models.ForeignKey(User, verbose_name = _('Autor')) post = models.ForeignKey(Post, verbose_name = _('Post')) message = models.TextField(_('Answer message'), blank = False) + modification_date = models.DateTimeField(_('Modification Date'), auto_now = True) answer_date = models.DateTimeField(_('Answer Date'), auto_now_add = True) class Meta: diff --git a/forum/static/js/forum.js b/forum/static/js/forum.js index 21f0cd5..7577e1e 100644 --- a/forum/static/js/forum.js +++ b/forum/static/js/forum.js @@ -15,15 +15,15 @@ function showForum(url, forum_id) { $('#forumModal').modal(); } -function getForm(url) { +function answer(id, url) { $.ajax({ url: url, success: function(data) { - $(".forum_form").html(data); + $("#post_"+id).find(".answer_post").html(data); } }); - $(".forum_form").show(); + $("#post_"+id).find(".answer_post").show(); } function showPosts(url, forum) { diff --git a/forum/templates/post/post_list.html b/forum/templates/post/post_list.html index d87a922..d6af5e7 100644 --- a/forum/templates/post/post_list.html +++ b/forum/templates/post/post_list.html @@ -2,12 +2,15 @@ {% if posts|length > 0 %} {% for post in posts %} -
{{ post.post_date }}
{{ post.message|linebreaks }}
+