Created
February 15, 2018 17:37
-
-
Save dura0ok/99ee1eb943817ec31dbe712d5ed1fe23 to your computer and use it in GitHub Desktop.
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.db import models | |
| from django.utils import timezone | |
| from django.contrib.auth.models import User | |
| class Post(models.Model): | |
| author = models.ForeignKey('auth.User') | |
| title = models.CharField(max_length=200) | |
| text = models.TextField() | |
| image = models.ImageField(upload_to='img') | |
| created_date = models.DateTimeField( | |
| default=timezone.now) | |
| published_date = models.DateTimeField( | |
| blank=True, null=True) | |
| def publish(self): | |
| self.published_date = timezone.now() | |
| self.save() | |
| def __str__(self): | |
| return self.title | |
| class Client(models.Model): | |
| user = models.OneToOneField(User) | |
| user_photo = models.ImageField(upload_to='img') | |
| class Comment(models.Model): | |
| author = models.ForeignKey(User, verbose_name='Автор') | |
| text = models.TextField(max_length=430, verbose_name='Комментарий') | |
| article_for = models.IntegerField() | |
| data = models.DateTimeField(auto_now_add=True) |
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
| {% extends 'base.html' %} | |
| {% block content %} | |
| <div class="art"> | |
| <a id="edit" href="/post/{{ post.id }}/edit">Редактировать статью</a> | |
| <h5>{{ post.title }}</h5> | |
| <h6>{{ post.published_date }}</h6> | |
| <p>{{ post.text|linebreaksbr }}</p> | |
| </div> | |
| <div class="comments"> | |
| {% for comment in commets %} | |
| <div class="comment"> | |
| <h4>{{ comment.author }}</h4> | |
| </i>{{ comment.data }} | |
| <p>{{ comment.text }}</p> | |
| </div> | |
| {% endfor %} | |
| </div> | |
| {% endblock %} |
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
| def comment(request): | |
| context = { | |
| 'commets': Comment.objects.filter(article_for=id) | |
| } | |
| return render(request, 'post.html', context=context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment