[UPDT] HELPDESK: Updated HelpDesk Module Models Objects Manager
This commit is contained in:
@@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from base.horilla_company_manager import HorillaCompanyManager
|
from base.horilla_company_manager import HorillaCompanyManager
|
||||||
from base.models import Company, Department, JobPosition, Tags
|
from base.models import Company, Department, JobPosition, Tags
|
||||||
from employee.models import Employee
|
from employee.models import Employee
|
||||||
|
from horilla import horilla_middlewares
|
||||||
from horilla.models import HorillaModel
|
from horilla.models import HorillaModel
|
||||||
from horilla_audit.methods import get_diff
|
from horilla_audit.methods import get_diff
|
||||||
from horilla_audit.models import HorillaAuditInfo, HorillaAuditLog
|
from horilla_audit.models import HorillaAuditInfo, HorillaAuditLog
|
||||||
@@ -250,10 +251,32 @@ class Attachment(HorillaModel):
|
|||||||
class FAQCategory(HorillaModel):
|
class FAQCategory(HorillaModel):
|
||||||
title = models.CharField(max_length=30)
|
title = models.CharField(max_length=30)
|
||||||
description = models.TextField(blank=True, null=True, max_length=255)
|
description = models.TextField(blank=True, null=True, max_length=255)
|
||||||
|
company_id = models.ForeignKey(
|
||||||
|
Company,
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
editable=False,
|
||||||
|
verbose_name=_("Company"),
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
objects = HorillaCompanyManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||||
|
selected_company = request.session.get("selected_company")
|
||||||
|
if (
|
||||||
|
not self.id
|
||||||
|
and not self.company_id
|
||||||
|
and selected_company
|
||||||
|
and selected_company != "all"
|
||||||
|
):
|
||||||
|
self.company_id = Company.find(selected_company)
|
||||||
|
|
||||||
|
super().save()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("FAQ Category")
|
verbose_name = _("FAQ Category")
|
||||||
verbose_name_plural = _("FAQ Categories")
|
verbose_name_plural = _("FAQ Categories")
|
||||||
@@ -267,11 +290,24 @@ class FAQ(HorillaModel):
|
|||||||
company_id = models.ForeignKey(
|
company_id = models.ForeignKey(
|
||||||
Company, null=True, editable=False, on_delete=models.PROTECT
|
Company, null=True, editable=False, on_delete=models.PROTECT
|
||||||
)
|
)
|
||||||
objects = HorillaCompanyManager(related_company_field="company_id")
|
objects = HorillaCompanyManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.question
|
return self.question
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
||||||
|
selected_company = request.session.get("selected_company")
|
||||||
|
if (
|
||||||
|
not self.id
|
||||||
|
and not self.company_id
|
||||||
|
and selected_company
|
||||||
|
and selected_company != "all"
|
||||||
|
):
|
||||||
|
self.company_id = Company.find(selected_company)
|
||||||
|
|
||||||
|
super().save()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("FAQ")
|
verbose_name = _("FAQ")
|
||||||
verbose_name_plural = _("FAQs")
|
verbose_name_plural = _("FAQs")
|
||||||
|
|||||||
Reference in New Issue
Block a user