1
0

models.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import datetime
  2. from django.db import models
  3. from django.core.validators import validate_unicode_slug
  4. from django.utils import timezone
  5. # Create your models here.
  6. #class ArticleCatagories(models.Model):
  7. # name = models.CharField(max_length=20)
  8. class Article(models.Model):
  9. title = models.CharField(
  10. max_length=50,
  11. unique=True,
  12. )
  13. CATEGORY_CHOICES = [
  14. ('Linux',
  15. (
  16. ('nx', 'Nginx'),
  17. )
  18. ),
  19. ('ot', 'Other'),
  20. ]
  21. category = models.CharField(
  22. max_length=2,
  23. choices=CATEGORY_CHOICES,
  24. #default=FOOBAR,
  25. )
  26. created = models.DateField(
  27. auto_now_add=True,
  28. editable=False,
  29. )
  30. updated = models.DateField(
  31. auto_now=True,
  32. editable=False,
  33. )
  34. slug = models.SlugField(
  35. db_index=True,
  36. unique=True,
  37. validators=[validate_unicode_slug],
  38. )
  39. description = models.TextField()
  40. def __str__(self):
  41. return self.title
  42. def published_this_week(self):
  43. return self.created >= timezone.now() - datetime.timedelta(days=7)
  44. def updated_this_week(self):
  45. return self.updated >= timezone.now() - datetime.timedelta(days=7)