avaaren

Modeli)))

Feb 24th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. from django.db import models
  2. from django.urls import reverse
  3. from django.db import models
  4. from django.utils import timezone
  5. from django.contrib.auth.models import User
  6.  
  7.  
  8. class Topic(models.Model):
  9. author = models.ForeignKey(User,
  10. related_name='topics',
  11. on_delete=models.CASCADE)
  12. title = models.CharField(max_length=100)
  13. slug = models.SlugField()
  14. image = models.ImageField(blank=True, null=True)
  15. topic_text = models.TextField(max_length=1024)
  16. created = models.DateTimeField(default=timezone.now)
  17. updated = models.DateTimeField(auto_now=True)
  18.  
  19. class Meta:
  20. ordering =['-created']
  21. def get_absolute_url(self):
  22. return reverse('help:topic_detail', args=[self.created.year,
  23. self.created.month, self.created.day, self.slug])
  24.  
  25.  
  26. class Comment(models.Model):
  27. author = models.ForeignKey(User,
  28. related_name='comments',
  29. on_delete=models.CASCADE)
  30. topic = models.ForeignKey(Topic,
  31. related_name='comments',
  32. on_delete=models.CASCADE)
  33. comment_text = models.CharField(max_length=300)
  34. created = models.DateTimeField(auto_now_add=True)
  35. updated = models.DateTimeField(auto_now=True)
Advertisement
Add Comment
Please, Sign In to add comment