我正在浏览股票记录模型的代码here,在 num_allocated 字段上方,它在评论中说,
#: The amount of stock allocated to orders but not fed back to the master
#: stock system. A typical stock update process will set the num_in_stock
#: variable to a new value and reset num_allocated to zero
Run Code Online (Sandbox Code Playgroud)
那么,当产品缺货时,我如何按照评论中指定的方式进行库存更新过程?我需要将 num_in_stock 变量设置为新值并将 num_allocated 设置为零。
到目前为止,如果订单正在发货,我会调用 EventHandler 类中的 consumer_stock_allocations() 方法,并且订单中产品的库存数量正在减少。
如果有人已经实现了这个,请分享一些代码或一些例子,因为我是 oscar 的新手。
我已经设置了一个 django-oscar 项目,我正在尝试配置 URL。我的目标是更改/catalogue为/catalog.
按照文件我已经添加app.py在myproject/app.py
我的项目/app.py
from django.conf.urls import url, include
from oscar import app
class MyShop(app.Shop):
# Override get_urls method
def get_urls(self):
urlpatterns = [
url(r'^catalog/', include(self.catalogue_app.urls)),
# all the remaining URLs, removed for simplicity
# ...
]
return urlpatterns
application = MyShop()
Run Code Online (Sandbox Code Playgroud)
我的项目/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from . import views
from .app import application
urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/', admin.site.urls),
url(r'', application.urls),
url(r'^index/$',views.index, name …Run Code Online (Sandbox Code Playgroud) 我目前正在以编程方式将产品导入到我的产品目录中,但是,我在上传每个产品的图像时遇到困难。我的代码如下所示:
# frobshop/custom_utils/product_importer.py
from oscar.apps.catalogue.models import Product
...
for product in my_product_import_list:
...
product_entry = Product()
product_entry.title = my_product_title
product_entry.product_class = my_product_class
product_entry.category = my_category
product_entry.primary_image = "product_images/my_product_filename.jpg"
product_entry.save()
Run Code Online (Sandbox Code Playgroud)
当我使用开发服务器检查时,产品标题和产品类别等详细信息已成功保存,但是,我不确定如何为每个产品设置图像。
整个product_images文件夹最初位于我的media目录之外,但由于我没有得到任何结果,我将图像的整个文件夹复制粘贴到目录中,media但仍然没有结果。我假设跳过了相当多的步骤,也许有一个关于如何在媒体目录中排列图像的约定。但是,我不确定在哪里可以找到这些步骤和约定。
settings.py这是我的文件中处理我安装的应用程序、媒体目录和静态文件的部分:
# frobshop/frobshop/settings.py
...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'compressor',
'widget_tweaks',
] + get_core_apps(['custom_apps.shipping', 'custom_apps.payment', 'custom_apps.checkout'])
...
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
MEDIA_ROOT = 'media'
MEDIA_URL = '/media/'
Run Code Online (Sandbox Code Playgroud)
为了进一步清楚起见,这是我的urls.py
from django.contrib import admin
from …Run Code Online (Sandbox Code Playgroud) 从https://django-oscar.readthedocs.io/en/2.0.4/internals/getting_started.html安装 django-oscar 时出现以下错误
设置.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'oscar',
'oscar.apps.analytics',
'oscar.apps.checkout',
'oscar.apps.address',
'oscar.apps.shipping',
'oscar.apps.catalogue',
'oscar.apps.catalogue.reviews',
'oscar.apps.partner',
'oscar.apps.basket',
'oscar.apps.payment',
'oscar.apps.offer',
'oscar.apps.order',
'oscar.apps.customer',
'oscar.apps.search',
'oscar.apps.voucher',
'oscar.apps.wishlists',
'oscar.apps.dashboard',
'oscar.apps.dashboard.reports',
'oscar.apps.dashboard.users',
'oscar.apps.dashboard.orders',
'oscar.apps.dashboard.catalogue',
'oscar.apps.dashboard.offers',
'oscar.apps.dashboard.partners',
'oscar.apps.dashboard.pages',
'oscar.apps.dashboard.ranges',
'oscar.apps.dashboard.reviews',
'oscar.apps.dashboard.vouchers',
'oscar.apps.dashboard.communications',
'oscar.apps.dashboard.shipping',
# 3rd-party apps that oscar depends on
'widget_tweaks',
'haystack',
'treebeard',
'sorl.thumbnail',
'django_tables2',
]
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
'URL': 'http://127.0.0.1:8983/solr',
'INCLUDE_SPELLING': True,
},
}
Run Code Online (Sandbox Code Playgroud)
运行 py .\manage.py migrate 或 py .\manage.py makemigrations 后出现以下错误 …
我想访问产品属性的值.我已经使用代码weight和类型定义了一个product属性float.在我的观点中,我试图访问它,如下所示:
def red(request):
basket = request.basket
weight_total = 0
for line in basket.all_lines():
weight = line.product.attributes.get(code = 'weight')
weight_total += weight.productattributevalue
Run Code Online (Sandbox Code Playgroud)
它不起作用并给出错误:
'ProductAttribute' object has no attribute 'productattributevalue'
Run Code Online (Sandbox Code Playgroud)
我试着研究奥斯卡的模型,但找不到解决方案.请帮忙.
我在Mac(小牛队)中使用Django-Oscar.并且一切看起来都很好,但它没有显示任何正确上传的图像.在一开始我认为这是一个解决问题,但它将图片保存在正确的文件夹中.所以这不是问题.然后我试图安装libjpeg,因为它是在安装教程中推荐的.
我卸下了枕头
pip uninstall pillow
Run Code Online (Sandbox Code Playgroud)
然后我用这个命令,我在网上找到安装libjpeg
brew install libjpeg
Run Code Online (Sandbox Code Playgroud)
然后我再次安装枕头,然后一切都是一样的.它仍然没有显示任何图像,终端显示已经安装了jpeg-8d
有人可以帮助我吗 谢谢
我正在尝试在 Django-oscar 中编写一种基于国家/地区和重量基础的运输方法。看来默认的运输方式也必须有这些
from oscar.apps.shipping.methods import Free, FixedPrice, NoShippingRequired
Run Code Online (Sandbox Code Playgroud)
我不需要上述任何一项,只会通过折扣提供运费折扣。
我如何通过repository.py编写,这样我就不会应用任何这些oscar.apps.shipping.methods import Free,FixedPrice,NoShippingRequired
所以我可以编写我的类存储库(CoreRepository):
不写
methods += [NoShippingRequired()]
methods += [FixedPrice()]
methods += [Free()]
Run Code Online (Sandbox Code Playgroud)
我编写的方法不是基于代码的,而是通过仪表板中的运输菜单实现的。我按照以下步骤设置了运费。
https://groups.google.com/forum/#!topic/django-oscar/H4tf20ujm8k
测试时,在“运输菜单”页面上,“手工交付”和我的基于重量的按国家/地区运输方法按钮都会显示给客户。这意味着即使客户来自国外,客户也可以单击手工交付按钮。我希望禁用“送货方式”页面上的“手工送货”按钮,因此客户根本无法选择它。
另一种选择是在此按钮上附加一条消息,让客户清楚地知道,单击该按钮意味着安排在预订后 1 周内从仓库取货。
如何向客户显示该消息?客户未进入付款页面。并且发送电子邮件以便可以在 7 天内领取物品?与 argos 类似,预订、购买、购物、付款和提货。所以我可以将“HandDelivery”的描述更改为预订。然后客户不付款,而是在取货时付款。但如何呢?
我已经在项目中添加了cash_on_delivery付款方式。但我想再增加一种方法。我该怎么做。目前,我有这样的结帐视图代码:
class PaymentDetailsView(PaymentDetailsView):
template_name = 'checkout/payment-details.html'
template_name_preview = 'checkout/preview.html'
def get_context_data(self, **kwargs):
ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
ctx['signature'] = gateway.hmac_gen(ctx)
ctx['amount'] = '%s' % ctx['order_total'].incl_tax
ctx['price'] = '%s' % ctx['basket'].lines.all()[0].price_incl_tax
ctx['source'] = ctx
return ctx
# def handle_payment_details_submission(self, request):
# # Validate the submitted forms
# shipping_address = self.get_shipping_address(
# self.request.basket)
# address_form = BillingAddressForm(shipping_address, request.POST)
#
# if address_form.is_valid():
# address_fields = dict(
# (k, v) for (k, v) in address_form.instance.__dict__.items()
# if not k.startswith('_') and not k.startswith('same_as_shipping'))
# self.checkout_session.bill_to_new_address(address_fields) …Run Code Online (Sandbox Code Playgroud) 我想对 Django Oscar 上的所有产品征收 18% 的税。实现这一目标的最佳且简单的方法是什么?
我已遵循此文档。
结账/tax.py
from decimal import Decimal as D
def apply_to(submission):
# Assume 7% sales tax on sales to New Jersey You could instead use an
# external service like Avalara to look up the appropriates taxes.
STATE_TAX_RATES = {
'NJ': D('0.07')
}
shipping_address = submission['shipping_address']
rate = D('0.18')
for line in submission['basket'].all_lines():
line_tax = calculate_tax(
line.line_price_excl_tax_incl_discounts, rate)
unit_tax = (line_tax / line.quantity).quantize(D('0.01'))
line.purchase_info.price.tax = unit_tax
# Note, we change the submission in …Run Code Online (Sandbox Code Playgroud) 我在分叉属于其他 Django 奥斯卡应用程序子集的 Django 奥斯卡应用程序时遇到问题。对于我正在关注的文档/教程,请查看此处。
我已经完成并成功分叉了未嵌套在其他应用程序中的应用程序,并相应地更新了我安装的应用程序。这是应用程序的子集,用于演示嵌套应用程序的一般模式
'dashboard_folder.dashboard.apps.DashboardConfig',
'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',
'oscar.apps.dashboard.offers.apps.OffersDashboardConfig',
Run Code Online (Sandbox Code Playgroud)
但是,文档(上面链接)没有明确概述如何调用嵌套应用程序。我认为它们可能会自动与它们的“父母”分叉,但是,一个简单的测试(下面的代码)证明并非如此:
如果我'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',改为
dashboard_folder.dashboard.reports.apps.ReportsDashboardConfig',
我收到以下错误:
ModuleNotFoundError: No module named 'dashboard_folder.dashboard.reports'
我想我会尝试一些关于如何调用嵌套应用程序来分叉它们的“有根据的”猜测,但是不幸的是,以下所有操作都失败了:
manage.py oscar_fork_app offers offers_folder
CommandError: There is no app with the label 'offers'
manage.py oscar_fork_app dashboard.offers offers_folder
CommandError: There is no app with the label 'dashboard.offers'
manage.py oscar_fork_app ReportsDashboard ReportsDashboard_folder
CommandError: There is no app with the label 'ReportsDashboard'
manage.py oscar_fork_app reportsdashboard ReportsDashboard_folder
CommandError: There is no app with the label 'reportsdashboard'
manage.py oscar_fork_app dashboard/reportsdashboard ReportsDashboard_folder
CommandError: …Run Code Online (Sandbox Code Playgroud) django ×10
django-oscar ×10
python ×4
image ×2
avalara ×1
country ×1
e-commerce ×1
python-3.x ×1