Files
goodtimes/manage_cms/models.py
rizwanisready db213d3228 wrong commit
2024-02-29 13:25:50 +05:30

160 lines
4.9 KiB
Python

from django.db import models
from taggit.managers import TaggableManager
from django_quill.fields import QuillField
from accounts.models import BaseModel, IAmPrincipal, IAmPrincipalType
from django.utils import timezone
from django.core.exceptions import ValidationError
from django.core.validators import FileExtensionValidator
# Create your models here.
class NewsAndArticlesCategory(BaseModel):
name = models.CharField(max_length=255)
class Meta:
db_table = "news_article_category"
def __str__(self):
return self.name
class NewsAndArticles(BaseModel):
title = models.CharField(max_length=255)
small_description = models.TextField(blank=True, null=True)
long_description = QuillField()
image_url = models.ImageField(upload_to="news_article", blank=True, null=True)
video_url = models.URLField(max_length=2000, blank=True, null=True)
article_category = models.ForeignKey(
NewsAndArticlesCategory,
related_name="%(class)s_category",
on_delete=models.CASCADE,
)
author = models.ForeignKey(
IAmPrincipal,
related_name="%(class)s_author",
null=True,
blank=True,
on_delete=models.SET_NULL,
)
tags = TaggableManager()
class Meta:
db_table = "news_article"
def __str__(self):
return self.title
class Newsletter(BaseModel):
title = models.CharField(max_length=255)
content = QuillField()
publication_date = models.DateField(auto_now_add=True)
is_published = models.BooleanField(default=False)
class Meta:
db_table = "newsletters"
ordering = ["-publication_date"]
def __str__(self):
return self.title
class FaqCategory(BaseModel):
name = models.CharField(max_length=255)
class Meta:
db_table = "faq_category"
def __str__(self):
return self.name
class Faqs(BaseModel):
faq_category = models.ForeignKey(
FaqCategory, related_name="faqs_category", null=True, on_delete=models.SET_NULL
)
question = models.TextField(max_length=255)
answer = models.TextField(blank=True, null=True)
class Meta:
db_table = "faq"
def __str__(self):
return self.question
class Organization(BaseModel):
title = models.CharField(max_length=255)
contact_us_email = models.EmailField(unique=True, blank=True, null=True)
instagram_handle = models.URLField(blank=True, null=True)
facebook_handle = models.URLField(blank=True, null=True)
linkedin_handle = models.URLField(blank=True, null=True)
logo_image = models.ImageField(blank=True, null=True, upload_to="organization/logo")
favicon_image = models.ImageField(
blank=True, null=True, upload_to="organization/favicon"
)
website_url = models.URLField(blank=True, null=True)
about_us = QuillField()
terms_condition = QuillField()
terms_condition_user = QuillField()
terms_condition_merchant = QuillField()
privacy_policy = QuillField()
privacy_policy_user = QuillField()
privacy_policy_merchant = QuillField()
subscription_agreement = QuillField()
license_agreement_user = QuillField()
license_agreement_merchant = QuillField()
class Meta:
db_table = "organization"
def __str__(self):
return self.title
class Education(BaseModel):
VIDEO = "Video"
MATERIAL = "Material"
CONTENT_TYPE_CHOICES = (
(VIDEO, "Video"),
(MATERIAL, "Material"),
)
content_type = models.CharField(max_length=20, choices=CONTENT_TYPE_CHOICES)
title = models.CharField(max_length=255)
description = models.TextField()
thumbnail = models.ImageField(upload_to="education", null=True, blank=True)
file = models.FileField(
upload_to="education",
null=True,
blank=True,
validators=[
FileExtensionValidator(
allowed_extensions=["pdf"], message="Only PDF files are allowed."
)
]
)
video_url = models.URLField(null=True, blank=True)
tags = TaggableManager(related_name="education_tags")
published_at = models.DateTimeField()
withdrawn_at = models.DateTimeField()
def clean(self):
current_date = timezone.now()
# if self.published_at and self.published_at < current_date:
# raise ValidationError("Published date should be in the future.")
if self.withdrawn_at and self.withdrawn_at < current_date:
raise ValidationError("Withdrawn date should be in the future.")
if (self.published_at and self.withdrawn_at and self.published_at > self.withdrawn_at):
raise ValidationError(
"Published date should be earlier than withdrawn date."
)
def is_publised(self):
current_date = timezone.now()
return self.published_at <= current_date and (
not self.withdrawn_at or self.withdrawn_at > current_date
)