Django商店与Django货币的集成
djangoshop-currencies的Python项目详细描述
Django Shop与django-currencies集成
简介
此模块允许django shop实现集成live 货币供给。这将允许你提供你的商店产品价格 使用用户选择的货币。
该模块目前与django v1.10.7兼容。这个 文档假设Django和 Django-SHOP。
发布历史
- 0.2.x-Django-SHOPv0.11.x兼容性
- 0.1.x-Django-SHOPv0.10.2兼容性
待办事项
请让我知道你有任何功能建议,或希望 执行下列任一操作:
- 修复下面的数据库初始化警告。
- 测试。
- 持续构建集成,包括与 各种python、django和django商店版本。
配置
请按照django-currencies的自述文件进行操作。 通过pip:pip install djangoshop-currencies安装此模块。
django商店货币系统已经扩展到使用django货币作为货币转换后端。 要启用此功能,您的货币配置必须满足以下要求:
- 使用^{tt2}填充ISO4217指数和符号$ (这将自动导入SHOP_CURRENCIES设置中设置的货币)
- 使用^{tt4}填充货币因子$ (这也将基础货币设置为SHOP_DEFAULT_CURRENCY)
- 某些货币在管理界面中设置为活动状态
警告
必须先初始化currences数据库表,然后任何django应用程序才能导入包含的货币类型。 不幸的是,./manage.py命令将在 安装的应用程序导致错误,使您无法运行./manage.py migrate等。
作为找到永久解决方案之前的解决方法:
- 创建一个最小设置文件,该文件将临时用于允许填充数据库的货币表。例如,one is included here。
- 运行python manage.py migrate --settings shop_currencies.min_settings(或使用最小设置文件)
- 满足要求1。&;2。在命令的上方附加--settings <min_settings>。
- 运行python manage.py migrate
- 运行python manage.py createsuperuser创建管理员用户
- 满足要求3。以上
创建后,我建议在初始化数据库时将基础货币作为固定设备丢弃,以便以后使用:
python manage.py dumpdata --indent 2 --output fixtures/currency.json --pks 1 currencies.currency python manage.py loaddata --settings shop_currencies.min_settings fixtures/currency.json
使用量
用提供的^{tt13}替换DefaultCartModifier。$ 在您的店铺设置中:
SHOP_CART_MODIFIERS=(# provides the default cart lines'shop_currencies.modifiers.CurrencyCartModifier',...
使用money conversion扩展,它提供to(code)函数,如下所示。 cart修饰符使用附加的base参数。
fromdjango.dbimportmodelsfromcurrencies.utilsimportget_currency_codefromshop_currencies.money.fieldsimportMoneyFieldclassMyModel(models.Model):unit_price=MoneyField()...defget_price(self,request,base=False):ifbase:returnself.unit_priceelse:session_currency_code=get_currency_code(request)returnself.unit_price.to(session_currency_code)