This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container-1 left"> | |
<div class="f-card content"> | |
<h2>{{page_obj.created_at}}</h2> | |
<p>{{page_obj.comment}}.</p> | |
<div class="text-left"> | |
<span class="pointer"> | |
{% if request.user in page_obj.likes.users.all%} | |
<!--Start of already liked--> | |
<a href={% url 'comment_vote' comment_id=page_obj.pk opition='like' %}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.mixins import LoginRequiredMixin | |
class Requirement(View): | |
form_class = my_forms.CommentForm | |
template_name = 'ktu/comment.html' | |
def get(self, request, *args, **kwargs): | |
form = self.form_class() | |
comment = my_models.Comment.objects.all() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentForm(forms.ModelForm): | |
class Meta: | |
model = my_models.Comment | |
fields = ('comment',) | |
widgets = { | |
'comment': forms.Textarea(attrs={'rows':5, 'cols':40}), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Like(models.Model): | |
''' like comment ''' | |
comment = models.OneToOneField(Comment, related_name="likes", on_delete=models.CASCADE) | |
users = models.ManyToManyField(User, related_name='requirement_comment_likes') | |
created_at = models.DateTimeField(auto_now_add=True) | |
updated_at = models.DateTimeField(auto_now=True) | |
def __str__(self): | |
return str(self.comment.comment)[:30] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comment(models.Model): | |
''' Main comment model''' | |
user = models.ForeignKey(User, related_name='comments', on_delete=models.CASCADE) | |
comment = models.TextField(validators=[MinLengthValidator(150)]) | |
created_at = models.DateTimeField(auto_now_add=True) | |
updated_at = models.DateTimeField(auto_now=True) | |
def get_total_likes(self): | |
return self.likes.users.count() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import AbstractUser | |
class User(AbstractUser): | |
DOCTOR = 1 | |
NURSE = 2 | |
SURGEN =3 | |
ROLE_CHOICES = ( | |
(DOCTOR, 'Doctor'), | |
(NURSE, 'Nurse'), |
NewerOlder