diff --git a/Interviewbook/admin.py b/Interviewbook/admin.py index 5984657..f8858cc 100644 --- a/Interviewbook/admin.py +++ b/Interviewbook/admin.py @@ -2,6 +2,15 @@ from .models import * # Register your models here. +class CommentAdmin(admin.ModelAdmin): + list_display = ('username', 'body', 'response', 'created_on', 'active') + list_filter = ('active', 'created_on') + search_fields = ('username', 'body') + actions = ['disapprove_comment'] + def disapprove_comment(self, request, queryset): + queryset.update(active=False) + admin.site.register(InterviewResponse) admin.site.register(Company) +admin.site.register(Comment) diff --git a/Interviewbook/forms.py b/Interviewbook/forms.py index 3de6b0c..d7fc5d2 100644 --- a/Interviewbook/forms.py +++ b/Interviewbook/forms.py @@ -1,3 +1,4 @@ +from django import forms from django.forms import ModelForm, Textarea from .models import * from django.contrib.auth.models import User @@ -21,3 +22,9 @@ class CompanyForm(ModelForm): class Meta: model = Company exclude =() + +class CommentForm(forms.ModelForm): + + class Meta: + model = Comment + fields = ('body', ) \ No newline at end of file diff --git a/Interviewbook/models.py b/Interviewbook/models.py index bb82dd9..e7ad7ba 100644 --- a/Interviewbook/models.py +++ b/Interviewbook/models.py @@ -26,3 +26,18 @@ def __str__(self): def increase(self): self.hits += 1 self.save() + +class Comment(models.Model): + response = models.ForeignKey(InterviewResponse, on_delete=models.CASCADE, related_name='comments') + username = models.CharField(max_length=200) + body = models.TextField(null=True) + created_on = models.DateTimeField(auto_now_add=True) + active = models.BooleanField(default=True) + replies = models + + class Meta: + ordering = ['created_on'] + + def __str__(self): + return 'Comment {} by {}'.format(self.body, self.username) + diff --git a/Interviewbook/templates/Interviewbook/response.html b/Interviewbook/templates/Interviewbook/response.html index 0d71f2a..0fba6be 100644 --- a/Interviewbook/templates/Interviewbook/response.html +++ b/Interviewbook/templates/Interviewbook/response.html @@ -31,7 +31,46 @@ No of rounds : {{response.rounds}} +
+ {{ comment.username }} + + {{ comment.created_on }} + +
+ {{ comment.body | linebreaks }} +