반응형
models>
from django.conf import settings
from django.db import models
# Create your models here.
User = settings.AUTH_USER_MODEL
class BlogPost(models.Model): # blogpost_set > queryset
# id = models.IntegerField() # pk
user = models.ForeignKey(User, default=1, null=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=120)
slug = models.SlugField(unique=True) # hello world > hello-world
content = models.TextField(null=True, blank=True)
publish_date = models.DateTimeField(
auto_now=False, auto_now_add=False, null=True, blank=True
)
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-publish_date", "-updated", "-timestamp"]
def get_absolute_url(self):
return f"/blog/{self.slug}"
def get_edit_url(self):
return f"{self.get_absolute_url()}/edit"
def get_delete_url(self):
return f"{self.get_absolute_url()}/delete"
반응형
'Python_WEB > Try_Django' 카테고리의 다른 글
[Django]Published and Draft Posts (0) | 2020.06.21 |
---|---|
[Django]Model Managers and Custom QuerySets (0) | 2020.06.21 |
[Django]Include with Arguments (0) | 2020.06.21 |
[Django]Include the Navbar (0) | 2020.06.21 |
[Django]Blog Post Navigation (0) | 2020.06.21 |