83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
from django import forms
|
|
from django.core.exceptions import ValidationError
|
|
from django.core import validators
|
|
from .models import (
|
|
Organization,
|
|
FaqCategory,
|
|
Faqs,
|
|
)
|
|
|
|
from module_project import constants
|
|
|
|
|
|
class OrganizationForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Organization
|
|
fields = [
|
|
"title",
|
|
"contact_us_email",
|
|
"instagram_handle",
|
|
"facebook_handle",
|
|
"linkedin_handle",
|
|
"logo_image",
|
|
"favicon_image",
|
|
"website_url",
|
|
]
|
|
|
|
labels = {
|
|
"title": "Organization Title",
|
|
"contact_us_email": "Contact Email",
|
|
"instagram_handle": "Instagram URL",
|
|
"facebook_handle": "Facebook URL",
|
|
"linkedin_handle": "LinkedIn URL",
|
|
"logo_image": "Organization Logo",
|
|
"favicon_image": "Favicon",
|
|
"website_url": "Website URL",
|
|
}
|
|
|
|
class AboutUsForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Organization
|
|
fields = ["about_us"]
|
|
labels = {"about_us": "Enter information about your organization:"}
|
|
|
|
class TermsAndConditionForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Organization
|
|
fields = ["terms_condition"]
|
|
labels = {"terms_condition": "Enter Terms and Conditions:"}
|
|
|
|
class PrivacyPolicyForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Organization
|
|
fields = ["privacy_policy"]
|
|
labels = {"privacy_policy": "Enter Privacy Police:"}
|
|
|
|
|
|
class FaqCategoryFrom(forms.ModelForm):
|
|
class Meta:
|
|
model = FaqCategory
|
|
fields = ["name"]
|
|
labels = {"name": "Category name"}
|
|
|
|
|
|
class FaqsForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Faqs
|
|
fields = [
|
|
# "faq_category",
|
|
"question",
|
|
"answer",
|
|
"active",
|
|
]
|
|
# labels = {"faq_category": "Category"}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
instance = kwargs.get("instance")
|
|
super().__init__(*args, **kwargs)
|
|
# Fetch the choices for the faq_category field from the database
|
|
# self.fields["faq_category"].queryset = FaqCategory.objects.all()
|
|
|
|
if instance is None:
|
|
# This is an add operation, exclude the 'active' field
|
|
self.fields.pop("active") |