login/register/post
This commit is contained in:
parent
6f18890739
commit
6fc506df2f
6 changed files with 283 additions and 108 deletions
|
|
@ -8,6 +8,7 @@ from django.conf import settings
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.timesince import timesince
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
|
@ -133,6 +134,12 @@ class Comment(models.Model):
|
|||
|
||||
@property
|
||||
def date(self):
|
||||
now = timezone.now()
|
||||
difference = now - self.created
|
||||
if difference <= timedelta(minutes=1):
|
||||
return "just now"
|
||||
return '%(time)s ago' % {'time': timesince(self.created).split(', ')[0]}
|
||||
return self.created.strftime('%B %d, %Y at %H:%M')
|
||||
return self.created.strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
def json(self):
|
||||
|
|
@ -143,5 +150,7 @@ class Comment(models.Model):
|
|||
data['name'] = self.name
|
||||
data['date'] = self.date
|
||||
data['text'] = self.text
|
||||
data['id'] = self.id
|
||||
data['published'] = self.is_published
|
||||
return data
|
||||
|
||||
|
|
|
|||
|
|
@ -43,13 +43,7 @@ def item(request, id):
|
|||
qs = qs.filter(q)
|
||||
comments = []
|
||||
for comment in qs:
|
||||
comments.append({
|
||||
"id": comment.id,
|
||||
"name": comment.name,
|
||||
"date": comment.date,
|
||||
"text": comment.text,
|
||||
"published": comment.is_published,
|
||||
})
|
||||
comments.append(comment.json())
|
||||
context['comments'] = mark_safe(json.dumps(comments))
|
||||
user = {}
|
||||
if request.user.is_staff:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue