SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db import models
  2. from django.utils import timezone
  3. from users.models import User
  4. from django.urls import reverse
  5.  
  6.  
  7. class Post(models.Model):
  8.     title = models.CharField('title', max_length=151, db_index=True)
  9.     content = models.TextField()
  10.     date_posted = models.DateTimeField(default=timezone.now)
  11.     author = models.ForeignKey(User, on_delete=models.CASCADE)
  12.  
  13.     class Meta:
  14.         verbose_name = 'Post'
  15.  
  16.     def __str__(self):
  17.         return self.title
  18.  
  19.     def get_absolute_url(self):
  20.         return reverse('post_detail', kwargs={'pk': self.pk})
  21.  
  22.  
  23. class Comment(models.Model):
  24. #   Оставляй описание классам
  25.     """
  26.     Модель: Комментария
  27.     """
  28.     post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, related_name='comments')
  29.     author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
  30.     content = models.TextField(max_length=160)
  31.     date_posted = models.DateTimeField(default=timezone.now)
  32.  
  33.     def __str__(self):
  34.         return self.content
  35.      
  36.     # Обязательно к каждой модели указывай class Meta:
  37.     class Meta:
  38.       verbose_name = 'Комментарий'
  39.       verbose_name_plural = 'Комментарии'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top