members.models
from django.db import models
# Create your models here.
from django.contrib.auth.models import User
from ckeditor.fields import RichTextField
from padonak_app.models import Readinglist
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
short_biography = RichTextField(max_length=100000,null=True,blank=True)
biography = RichTextField(max_length=100000,null=True,blank=True)
profile_photo = models.ImageField(upload_to='media/AUTHOR_PHOTOS/', null=True, blank=True)
website_url = models.URLField(max_length=1000,null=True, blank=True)
twitter = models.URLField(max_length=1000,null=True, blank=True)
date_of_birth = models.DateTimeField(auto_now_add=True,null=True,blank=True)
date_of_death = models.DateTimeField(auto_now_add=True,null=True,blank=True)
reading_list = models.ForeignKey(ReadingList, on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return self.user.username
class Author(models.Model):
author = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
short_biography = RichTextField(max_length=100000,null=True,blank=True)
biography = RichTextField(max_length=100000,null=True,blank=True)
profile_photo = models.ImageField(upload_to='media/AUTHOR_PHOTOS/', null=True, blank=True)
website_url = models.URLField(max_length=1000,null=True, blank=True)
twitter = models.URLField(max_length=1000,null=True, blank=True)
def __str__(self):
return self.user.username
padonak_app.models
from django.db import models
# Create your models here.
from django.urls import reverse
from ckeditor.fields import RichTextField
from import_export import resources
from members.models import Profile
from django.contrib.auth.models import User
class AwardsPrizes(models.Model):
title = models.CharField(max_length=300,blank=True)
slug = models.SlugField(max_length=300,blank=True)
description = RichTextField(max_length=30000,blank=True)
awarded_date = models.DateTimeField(auto_now_add=False, blank=True)
def get_absolute_url(self):
return reverse('padonak_app:awardandprize', args=[self.slug])
def __str__(self):
return self.title
class Publisher(models.Model):
name = models.CharField(max_length=300,blank=True)
slug = models.SlugField(max_length=300,blank=True)
description = RichTextField(max_length=30000,blank=True)
logo_image = models.ImageField(upload_to='media/PUBLISHER_LOGOS/', blank=True)
website_url = models.URLField(max_length=1000, null=True, blank=True)
def get_absolute_url(self):
return reverse('padonak_app:publisher_details', args=[self.slug])
def __str__(self):
return self.name
class Genres(models.Model):
name = models.CharField(max_length=300,blank=True)
slug = models.SlugField(max_length=300,blank=True)
genre_icon = models.ImageField(upload_to='media/GENRES_ICONS/')
def get_absolute_url(self):
return reverse('padonak_app:genre_details', args=[self.slug])
def __str__(self):
return self.name
class Languages(models.Model):
language = models.CharField(max_length=100, null=True,blank=True)
def __str__(self):
return self.language
class Book(models.Model):
class NewManager(models.Manager):
def get_queryset(self):
return super().get_queryset() .filter(status='published')
options = (('draft','Draft'),('published','Published'),)
title = models.CharField(max_length=300,blank=True)
slug = models.SlugField(max_length=300,blank=True)
author = models.ManyToManyField(User, null=True,blank=True)
genre = models.ManyToManyField(Genres, null=True, blank=True)
edition = models.CharField(max_length=300,blank=True)
format_type = models.CharField(max_length=300,blank=True)
languages = models.ManyToManyField(Languages, max_length=300,blank=True)
featured_image = models.ImageField(upload_to='media/FEATURED_IMAGES/',blank=True)
description = RichTextField(max_length=30000,blank=True)
published_date_re = models.DateTimeField(auto_now_add=False, blank=True)
published_date_or = models.DateTimeField(auto_now_add=False, blank=True)
#date_started_reading = models.DateTimeField(auto_now_add=False, blank=True)
#date_finished_reading = models.DateTimeField(auto_now_add=False, blank=True)
publisher = models.ForeignKey(Publisher,on_delete=models.CASCADE,max_length=300,blank=True)
isbn = models.CharField(max_length=100, blank=True)
isbn_10 = models.CharField(max_length=100, blank=True)
isbn_13 = models.CharField(max_length=100, blank=True)
pages = models.CharField(max_length=300,blank=True)
amazon_link = models.URLField(max_length=2000,null=True,blank=True)
walmart_link = models.URLField(max_length=2000,null=True,blank=True)
awards_prizes = models.ManyToManyField(AwardsPrizes,max_length=400,null=True,blank=True)
reading_list = models.ManyToManyField(User, related_name="reading_list",default=None,blank=True)
status = models.CharField(max_length=10, choices=options, default='draft')
objects = models.Manager()
newmanager = NewManager()
def get_absolute_url(self):
return reverse('padonak_app:book', args=[self.slug])
def __str__(self):
return self.title
metadata = {
'title':title,
'description':description
}
class ReadingList(models.Model):
title = models.CharField(max_length=300,blank=True)
slug = models.SlugField(max_length=300,blank=True)
books = models.ManyToManyField(Book, null=True,blank=True)
def get_absolute_url(self):
return reverse('members:reading_list', args=[self.slug])
def __str__(self):
return self.title