From edf1118f9f024bf680e5b54bcb183486ddd46cfa Mon Sep 17 00:00:00 2001 From: phzhik Date: Sat, 19 Aug 2023 20:01:30 +0400 Subject: [PATCH] * null-check for Checklist.category * fixed missing deps * cleanup --- poizonstore/settings.py | 1 + store/admin.py | 2 -- store/models.py | 7 ++++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poizonstore/settings.py b/poizonstore/settings.py index 0b6a872..8a60c8f 100644 --- a/poizonstore/settings.py +++ b/poizonstore/settings.py @@ -68,6 +68,7 @@ INSTALLED_APPS = [ 'djoser', 'debug_toolbar', 'django_filters', + 'mptt', 'store' ] diff --git a/store/admin.py b/store/admin.py index dccc5ff..88d1cd4 100644 --- a/store/admin.py +++ b/store/admin.py @@ -2,8 +2,6 @@ from django.contrib import admin from django.contrib.admin import display from mptt.admin import MPTTModelAdmin -from .models import Category, Checklist, GlobalSettings, PaymentMethod, Promocode, User, Image, Client - from .models import Category, Checklist, GlobalSettings, PaymentMethod, Promocode, User, Image diff --git a/store/models.py b/store/models.py index ddd6468..28989cb 100644 --- a/store/models.py +++ b/store/models.py @@ -394,9 +394,10 @@ class Checklist(models.Model): price += self.commission_rub # Add commission of bottom-most category - category = self.category.get_ancestors(ascending=True, include_self=True).first() - category_commission = getattr(category, 'commission', 0) - price += category_commission * self.price_rub / 100 + if self.category: + category = self.category.get_ancestors(ascending=True, include_self=True).first() + category_commission = getattr(category, 'commission', 0) + price += category_commission * self.price_rub / 100 return max(0, math.ceil(price))