commit
f56705ee4e
|
@ -170,3 +170,6 @@ WAGTAILSEARCH_BACKENDS = {
|
||||||
# Base URL to use when referring to full URLs within the Wagtail admin backend -
|
# Base URL to use when referring to full URLs within the Wagtail admin backend -
|
||||||
# e.g. in notification emails. Don't include '/admin' or a trailing slash
|
# e.g. in notification emails. Don't include '/admin' or a trailing slash
|
||||||
WAGTAILADMIN_BASE_URL = "http://example.com"
|
WAGTAILADMIN_BASE_URL = "http://example.com"
|
||||||
|
|
||||||
|
# STORE SETTINGS
|
||||||
|
PRODUCTS_PER_PAGE = 6
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.core.paginator import (
|
||||||
|
Paginator,
|
||||||
|
EmptyPage
|
||||||
|
)
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from modelcluster.models import ClusterableModel
|
from modelcluster.models import ClusterableModel
|
||||||
from modelcluster.fields import ParentalKey
|
from modelcluster.fields import ParentalKey
|
||||||
|
@ -6,13 +11,9 @@ from wagtail.admin.panels import (
|
||||||
FieldPanel,
|
FieldPanel,
|
||||||
InlinePanel
|
InlinePanel
|
||||||
)
|
)
|
||||||
from wagtail.models import (
|
from wagtail.models import Page
|
||||||
Orderable,
|
|
||||||
Page
|
|
||||||
)
|
|
||||||
from wagtail import fields as wagtail_fields
|
from wagtail import fields as wagtail_fields
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
from taggit.models import Tag
|
|
||||||
|
|
||||||
|
|
||||||
class ProductAuthor(models.Model):
|
class ProductAuthor(models.Model):
|
||||||
|
@ -62,17 +63,14 @@ class ProductTemplate(ClusterableModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def get_images(self):
|
|
||||||
return self.images.objects.all().values_list("image")
|
|
||||||
|
|
||||||
panels = [
|
panels = [
|
||||||
FieldPanel("category"),
|
FieldPanel("category"),
|
||||||
FieldPanel("author"),
|
FieldPanel("author"),
|
||||||
FieldPanel("family"),
|
|
||||||
FieldPanel('title'),
|
FieldPanel('title'),
|
||||||
FieldPanel('code'),
|
FieldPanel('code'),
|
||||||
FieldPanel('description'),
|
FieldPanel('description'),
|
||||||
InlinePanel("images")
|
InlinePanel("images"),
|
||||||
|
FieldPanel("tags"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,9 +90,16 @@ class Product(ClusterableModel):
|
||||||
FieldPanel("template"),
|
FieldPanel("template"),
|
||||||
FieldPanel("price"),
|
FieldPanel("price"),
|
||||||
InlinePanel("param_values"),
|
InlinePanel("param_values"),
|
||||||
InlinePanel("available")
|
FieldPanel("available")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def main_image(self):
|
||||||
|
images = self.template.images.all()
|
||||||
|
print(images)
|
||||||
|
if images:
|
||||||
|
return images.first().image
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
return f"{self.template.title} - {self.price}"
|
return f"{self.template.title} - {self.price}"
|
||||||
|
@ -113,13 +118,24 @@ class ProductListPage(Page):
|
||||||
tags = TaggableManager(blank=True)
|
tags = TaggableManager(blank=True)
|
||||||
|
|
||||||
def _get_items(self):
|
def _get_items(self):
|
||||||
if self.tags:
|
if self.tags.all():
|
||||||
return Product.objects.filter(available=True, template__tags__in=self.tags.all())
|
return Product.objects.filter(available=True, template__tags__in=self.tags.all())
|
||||||
return Product.objects.filter(available=True)
|
return Product.objects.filter(available=True)
|
||||||
|
|
||||||
def get_context(self, request):
|
def get_context(self, request):
|
||||||
context = super().get_context(request)
|
context = super().get_context(request)
|
||||||
context["items"] = self._get_items()
|
items = self._get_items()
|
||||||
|
if not items:
|
||||||
|
return context
|
||||||
|
|
||||||
|
paginator = Paginator(items, settings.PRODUCTS_PER_PAGE)
|
||||||
|
page_number = request.GET.get("page", 1)
|
||||||
|
try:
|
||||||
|
page = paginator.page(page_number)
|
||||||
|
except EmptyPage:
|
||||||
|
page = paginator.page(1)
|
||||||
|
context["items"] = page.object_list
|
||||||
|
context["page"] = page
|
||||||
return context
|
return context
|
||||||
|
|
||||||
content_panels = Page.content_panels + [
|
content_panels = Page.content_panels + [
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
<div class="card" style="width: 15rem;">
|
|
||||||
<img class="card-img-top" src="..." alt="Card image cap">
|
<div class="card h-100" style="width: 15rem;">
|
||||||
|
<div class="card-header">{{item.title}}</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">Card title</h5>
|
<img src="{{item.main_image.url}}" class="rounded mx-auto d-block" style="width: 10rem; height: 10 rem;">
|
||||||
<a href="#" class="btn btn-primary">Details</a>
|
<p class="card-text">{{item.description}}</p>
|
||||||
<a href="#" class="btn btn-success">
|
|
||||||
|
<div class="text-end">
|
||||||
|
<a href="#" class="btn btn-outline-primary">Details</a>
|
||||||
|
<a href="#" class="btn btn-outline-success">
|
||||||
<img src = "{% static 'images/icons/cart.svg' %}" alt="Koszyk"/>
|
<img src = "{% static 'images/icons/cart.svg' %}" alt="Koszyk"/>
|
||||||
</a>
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,17 +3,28 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container mb-3">
|
||||||
<div class="row mb-3">
|
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||||
<div class="col-sm">
|
{% for item in items %}
|
||||||
{% include 'store/partials/product_card.html' %}
|
<div class="col">
|
||||||
</div>
|
{% include 'store/partials/product_card.html' %}
|
||||||
<div class="col-sm">
|
</div>
|
||||||
{% include 'store/partials/product_card.html' %}
|
{% endfor %}
|
||||||
</div>
|
|
||||||
<div class="col-sm">
|
|
||||||
{% include 'store/partials/product_card.html' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<nav aria-label="Page navigation example">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
<li class="page-item {% if not page.has_previous %} disabled {% endif %}">
|
||||||
|
<a class="page-link" href="?page={{page.number|add:-1}}" tabindex="-1" {% if not page.has_previous %}aria-disabled="true"{% endif %}>Previous</a>
|
||||||
|
</li>
|
||||||
|
{% for pg in page.paginator.get_elided_page_range %}
|
||||||
|
<li class="page-item {% if pg == page.number %}active{% endif %}"><a class="page-link" href="?page={{pg}}">{{pg}}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
<li class="page-item {% if not page.has_next %} disabled {% endif %}">
|
||||||
|
<a class="page-link" {% if not page.has_next %}aria-disabled="true"{% endif %} href="?page={{page.number|add:1}}">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Ładowanie…
Reference in New Issue