from django.db import models
from redactor.fields import RedactorField
# Create your models here.
class AuthorManager(models.Manager):
def get_by_natural_key(self, name, avatar,degree):
return self.get(name=name, avatar=avatar, degree=degree)
class Category(models.Model):
title = models.CharField(max_length=250)
parent_category = models.ForeignKey('self', null=True, blank=True)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.title
class Meta(object):
verbose_name = 'Category'
verbose_name_plural = 'Categories'
class Author(models.Model):
objects = AuthorManager()
name = models.CharField(max_length=250)
avatar = models.ImageField(upload_to='media/avatar/%Y/%m/%d')
degree = models.CharField(max_length=250)
biography = RedactorField()
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.name
def natural_key(self):
return (self.name, self.avatar, self.degree)
class Meta(object):
unique_together = (('name', 'avatar','degree'),)
class Post(models.Model):
title = models.CharField(max_length=250)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
content = RedactorField(blank=True, null=True)
audio = models.FileField(upload_to='media/audio/%Y/%m/%d', blank=True, null=True)
video = models.FileField(upload_to='media/video/%Y/%m/%d', blank=True, null=True)
author = models.ForeignKey(Author, on_delete=models.CASCADE, blank=True, null=True)
preview = models.ImageField(upload_to='media/preview/%Y/%m/%d',blank=True, null=True)
view_count = models.IntegerField(blank=True, null=True)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.title
class Page(models.Model):
title = models.CharField(max_length=250)
content = RedactorField(blank=True, null=True)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.title