import datetime
from django.db import models
from django.core.validators import validate_unicode_slug
from django.utils import timezone
# Create your models here.

#class ArticleCatagories(models.Model):
#    name = models.CharField(max_length=20)


class Article(models.Model):
    title = models.CharField(
        max_length=50,
        unique=True,
    )

    CATEGORY_CHOICES = [
        ('Linux',
            (
                ('nx', 'Nginx'),
            )
        ),
        ('ot', 'Other'),
    ]
    category = models.CharField(
        max_length=2,
        choices=CATEGORY_CHOICES,
        #default=FOOBAR,
    )

    created = models.DateField(
        auto_now_add=True,
        editable=False,
    )

    updated = models.DateField(
        auto_now=True,
        editable=False,
    )

    slug = models.SlugField(
        db_index=True,
        unique=True,
        validators=[validate_unicode_slug],
    )

    description = models.TextField()

    keywords = models.CharField(
        max_length=50,
    )

    published = models.BooleanField(
        default = False,
    )

    content = models.TextField()


    def __str__(self):
        return self.title

    def published_this_week(self):
        return self.created >= timezone.now() - datetime.timedelta(days=7)

    def updated_this_week(self):
        return self.updated >= timezone.now() - datetime.timedelta(days=7)
