Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TechnologyDetailView(DetailView):
- model = Technology
- def get_queryset(self):
- group_permissions =
- Permission.objects.filter(group__user=self.request.user)
- query = Technology.objects.filter(pk=self.kwargs['pk'],
- is_active=True, permission__in=group_permissions)
- for tech in query:
- comments = Comment.objects.filter(technology=tech)
- now = datetime.now()
- for comment in comments:
- comment.timestamp = datetime.strptime('Jun 1 2005 1:33PM',
- '%b %d %Y %I:%M%p')
- print(comment.timestamp)
- age = now - comment.timestamp
- if age < 604800:
- comment.is_removable = True
- else:
- comment.is_removable = False
- return query
- <h3>Comments</h3>
- {% for comment in technology.comment_set.all %}
- <div class="row" style="border-bottom-style:solid;
- border-bottom-width:1px; border-color:gray;">
- <h6 style="font-weight:bold">Written by {{
- comment.user.name }}
- on {{ comment.timestamp }}</h6>
- <span>{{ comment.content|breaks }}</span>
- <p>{{ comment.timestamp | timesince }}</p>
- {% if comment.user == request.user %}
- <a class="modal-trigger right"
- href="#modal_{{ comment.pk }}">Delete Comment</a>
- {% endif %}
- <div id="modal_{{ comment.pk }}" class="modal">
- <div class="modal-content">
- <iframe frameborder="0"
- id="encoder_iframe" height=300px width="100%" src="{% url 'delete-
- comment' comment.pk %}"></iframe>
- </div>
- </div>
- </div>
- {% empty %}
- <p>There are no comments</p>
- {% endfor %}
- <br>
- <h5>Add new Comment</h5>
- <iframe frameborder="0" id="encoder_iframe"
- height=300px width="100%" src="{% url 'add-comment' technology.pk %}">
- </iframe>
- </div>
- </div>
- </div>
- # Comment model
- class Comment(models.Model):
- user = models.ForeignKey(User, null=True)
- technology = models.ForeignKey(Technology, null=True)
- parent = models.ForeignKey('self', null=True, blank=True)
- content = models.TextField(null=True)
- timestamp = models.DateTimeField(null=True)
- is_active = models.BooleanField(default=True)
Add Comment
Please, Sign In to add comment