Commit 434cb5d2 authored by Luis García's avatar Luis García
Browse files

Update models for blog app

parent 62fd1d6e
......@@ -3,6 +3,20 @@ from django.contrib.auth.models import User
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
# Model for category
class Category(models.Model):
name = models.CharField(verbose_name='Name', max_length=50)
description = models.TextField(verbose_name="Description")
created = models.DateTimeField(auto_now_add=True, verbose_name='Created date')
visible = models.BooleanField(verbose_name='visible', default=True)
class Meta():
verbose_name = 'Category'
verbose_name_plural = 'Categories'
def __str__(self):
return self.name
# Model for Post
class Post(models.Model):
slug = models.SlugField(verbose_name="Slug", unique=True)
......@@ -10,11 +24,14 @@ class Post(models.Model):
first_paragraph = models.TextField(verbose_name="First paragraph")
content = RichTextUploadingField(verbose_name='Content')
image = models.ImageField(verbose_name="Image", upload_to='posts/%Y-%m/')
pin_up = models.BooleanField(verbose_name="Pin up")
order = models.IntegerField(verbose_name="Order", default=1)
owner = models.ForeignKey(User, verbose_name='Owner', on_delete=models.CASCADE)
pin_up = models.BooleanField(verbose_name="Pin up", default=False)
comments = models.BooleanField(verbose_name="Comments", default=True)
#order = models.IntegerField(verbose_name="Order", default=1)
owner = models.ForeignKey(User, verbose_name='Owner', on_delete=models.CASCADE, related_name='Posts')
category = models.ForeignKey(Category, verbose_name='Category', on_delete=models.CASCADE, related_name='Posts')
created = models.DateTimeField(auto_now_add=True, verbose_name='Created date')
updated = models.DateTimeField(auto_now=True, verbose_name='Updated date')
visible = models.BooleanField(verbose_name='visible', default=True)
class Meta():
verbose_name = 'Post'
......@@ -29,8 +46,8 @@ class Comment(models.Model):
content = models.TextField(verbose_name="Content")
username = models.CharField(verbose_name='User name', max_length=50)
email = models.EmailField(verbose_name="Email")
post = models.ForeignKey(Post, verbose_name="Post", on_delete=models.CASCADE)
parent = models.ForeignKey('self', verbose_name="Parent", on_delete=models.CASCADE, blank=True, null=True)
post = models.ForeignKey(Post, verbose_name="Post", on_delete=models.PROTECT, related_name='Comments')
parent = models.ForeignKey('self', verbose_name="Parent", on_delete=models.CASCADE, related_name='Replies', blank=True, null=True)
created = models.DateTimeField(auto_now_add=True, verbose_name='Created date')
class Meta():
......@@ -38,4 +55,30 @@ class Comment(models.Model):
verbose_name_plural = 'Comments'
def __str__(self):
return self.content
\ No newline at end of file
return self.content
# Model for Tag
class Tag(models.Model):
name = models.CharField(verbose_name='Name', max_length=50, unique=True)
description = models.TextField(verbose_name="Description")
created = models.DateTimeField(auto_now_add=True, verbose_name='Created date')
class Meta():
verbose_name = 'Tag'
verbose_name_plural = 'Tags'
def __str__(self):
return self.name
# Model for Post Tag
class PostTag(models.Model):
post = models.ForeignKey(Post, verbose_name="Post", on_delete=models.PROTECT, related_name='Tags')
tag = models.ForeignKey(Tag, verbose_name="Tag", on_delete=models.CASCADE, related_name='Posts')
class Meta():
unique_together = (('post', 'tag'),)
verbose_name = 'Post tag'
verbose_name_plural = 'Post tags'
def __str__(self):
return self.post + ' - ' + self.tag
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment