feat: new dynamic pages in admin panel
This commit is contained in:
+33
-2
@@ -3,12 +3,19 @@ import random
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
from django.views.generic import ListView, TemplateView
|
||||
from django.views.generic import DetailView, ListView, TemplateView
|
||||
|
||||
from apps.products.models import SubProduct
|
||||
|
||||
from .forms import ContactForm
|
||||
from .models import AboutSection, ContactSubmission, FAQEntry, HeroSection, HomepageSection
|
||||
from .models import (
|
||||
AboutSection,
|
||||
ContactSubmission,
|
||||
CustomPage,
|
||||
FAQEntry,
|
||||
HeroSection,
|
||||
HomepageSection,
|
||||
)
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
@@ -90,3 +97,27 @@ class ContactView(View):
|
||||
{"success": False, "errors": errors, "captcha_question": captcha_question},
|
||||
status=400,
|
||||
)
|
||||
|
||||
|
||||
class CustomPageView(DetailView):
|
||||
model = CustomPage
|
||||
template_name = "pages/custom_page.html"
|
||||
context_object_name = "custom_page"
|
||||
slug_url_kwarg = "slug"
|
||||
|
||||
def get_queryset(self):
|
||||
return CustomPage.objects.filter(is_published=True)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
ctx["page_sections"] = (
|
||||
self.object.sections.filter(is_active=True)
|
||||
.prefetch_related("items")
|
||||
.order_by("order")
|
||||
)
|
||||
ctx["sub_products"] = (
|
||||
SubProduct.objects.filter(is_active=True, show_on_homepage=True)
|
||||
.select_related("main_product")
|
||||
.order_by("homepage_order", "order")
|
||||
)
|
||||
return ctx
|
||||
|
||||
Reference in New Issue
Block a user