from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse

# Create your models here.


class Post(models.Model):
    title = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255,unique=True)
    #meusite.com/blog;introducao-ao-django
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ("-created",)


    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("note:detail", kwargs={"slug": self.slug})

[((173, 205), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(255)'}), '(max_length=255)\n', (189, 205), False, 'from django.db import models\n'), ((217, 262), 'django.db.models.SlugField', 'models.SlugField', ([], {'max_length': '(255)', 'unique': '(True)'}), '(max_length=255, unique=True)\n', (233, 262), False, 'from django.db import models\n'), ((318, 367), 'django.db.models.ForeignKey', 'models.ForeignKey', (['User'], {'on_delete': 'models.CASCADE'}), '(User, on_delete=models.CASCADE)\n', (335, 367), False, 'from django.db import models\n'), ((379, 397), 'django.db.models.TextField', 'models.TextField', ([], {}), '()\n', (395, 397), False, 'from django.db import models\n'), ((412, 451), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now_add': '(True)'}), '(auto_now_add=True)\n', (432, 451), False, 'from django.db import models\n'), ((466, 501), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'auto_now': '(True)'}), '(auto_now=True)\n', (486, 501), False, 'from django.db import models\n'), ((651, 701), 'django.urls.reverse', 'reverse', (['"""note:detail"""'], {'kwargs': "{'slug': self.slug}"}), "('note:detail', kwargs={'slug': self.slug})\n", (658, 701), False, 'from django.urls import reverse\n')]