gpt4 book ai didi

python - Oscar 提供应用覆盖福利功能冲突错误

转载 作者:太空宇宙 更新时间:2023-11-04 04:10:47 26 4
gpt4 key购买 nike

我用的是 Oscar 1.6.4 版本。我想覆盖 oscar.app.offer.benefits.py 中的 PercentageDiscountBenefit。但是发生冲突错误。如何覆盖此功能?

from oscar.core.loading import get_classes

CorePercentageDiscountBenefit, CoreAbsoluteDiscountBenefit = get_classes('offer.benefits', ['PercentageDiscountBenefit', 'AbsoluteDiscountBenefit'])


class PercentageDiscountBenefit(CorePercentageDiscountBenefit):

def apply(self, basket, condition, offer, discount_amount=None,
max_total_discount=None):

print(
"\n\n\n\n",
"PRINT SOMETHING",
"\n\n\n\n",
)
return super().apply(basket, condition, offer, discount_amount,
max_total_discount)


class AbsoluteDiscountBenefit(CoreAbsoluteDiscountBenefit):

def apply(self, basket, condition, offer, discount_amount=None,
max_total_discount=None):

print(
"\n\n\n\n",
"PRINT SOMETHING",
"\n\n\n\n",
)
return super().apply(basket, condition, offer, discount_amount,
max_total_discount)

错误日志

RuntimeError at /basket/

Conflicting 'percentagediscountbenefit' models in application 'offer': <class 'oscar.apps.offer.benefits.PercentageDiscountBenefit'> and <class 'oscar_apps.offer.benefits.PercentageDiscountBenefit'>.

Request Method: GET
Request URL: http://localhost:8000/basket/
Django Version: 1.11.9
Exception Type: RuntimeError
Exception Value:

Conflicting 'percentagediscountbenefit' models in application 'offer': <class 'oscar.apps.offer.benefits.PercentageDiscountBenefit'> and <class 'oscar_apps.offer.benefits.PercentageDiscountBenefit'>.

Exception Location: /home/seyidov/PycharmProjects/Backend/embahome-backend/.venv/lib/python3.5/site-packages/django/apps/registry.py in register_model, line 224
Python Executable: /home/seyidov/PycharmProjects/Backend/embahome-backend/.venv/bin/python
Python Version: 3.5.2
Python Path:

['/home/seyidov/PycharmProjects/Backend/embahome-backend',
'/home/seyidov/PycharmProjects/Backend/embahome-backend',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/home/seyidov/PycharmProjects/Backend/embahome-backend/.venv/lib/python3.5/site-packages',
'/home/seyidov/Documents/Programs/pycharm-2018.2.4/helpers/pycharm_matplotlib_backend',
'/home/seyidov/PycharmProjects/Backend/embahome-backend']

最佳答案

您不能以这种方式覆盖福利等级。如果您想创建一个将不同逻辑应用于核心利益的自定义利益,您需要创建自己的类,它是核心 Benefit 模型的代理:

from oscar.apps.offer import models

class CustomPercentageDiscountBenefit(models.Benefit):

class Meta:
proxy = True

def apply(self, basket, condition, offer, discount_amount=None, max_total_discount=None):
# Apply your benefit here

这在 more detail in the documentation 中有解释.

关于python - Oscar 提供应用覆盖福利功能冲突错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56304171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com