在我的设置文件中,我定义为
SHOP_ADDRESS_MODEL = 'app.accounts.models.Address'
SHOP_PRODUCT_MODEL = 'app.products.models.Product'
但我得到这样的错误
ImproperlyConfigured: Error importing backend app.products.models: "cannot import name AddressModel". Check your SHOP_PRODUCT_MODEL settings
当我使用python manage.py runserver
运行应用程序时,它运行正常。但是我在使用gunicorn
运行时遇到此错误。我在gunicorn配置中包含了virtualenv路径
产品/ models.py
from decimal import Decimal, InvalidOperation
from django.db import models
from django.contrib import admin
from django.conf import settings
from shop.models_bases import BaseProduct
from app.utils import is_foreign
from haystack import indexes
def safewrite(s):
try:
with open("foreigntest.txt",'a') as f:
f.write(s)
f.write('\n')
except:
print "(error)"
print s
class Product(BaseProduct, indexes.Indexable):
# General fields
part_number = models.CharField(max_length=255)
category = models.CharField(max_length=255, blank=True, null=True)
summary = models.TextField(blank=True, null=True)
def get_price(self, request=None):
safewrite("get_price() REQUEST")
if is_foreign(request):
safewrite("FOREIGN")
try:
return Decimal(self.curr_intl_base_price_a_stored)
except InvalidOperation:
return Decimal(0)
else:
safewrite("NO")
try:
return Decimal(self.curr_domestic_base_price_a_stored)
except InvalidOperation:
return Decimal(0)
def get_price_b(self, request=None):
safewrite("get_price_b() REQUEST")
if is_foreign(request):
safewrite("FOREIGN")
try:
return Decimal(self.curr_intl_base_price_b_stored)
except InvalidOperation:
return Decimal(0)
else:
safewrite("NO")
try:
return Decimal(self.curr_domestic_base_price_b_stored)
except InvalidOperation:
return Decimal(0)
# webmfg fields:
AM_Number = models.CharField(max_length=255, blank=True, null=True)
Angle_of_Incidence = models.CharField(max_length=255, blank=True, null=True)
BW_Spec_minus = models.CharField(max_length=255, blank=True, null=True)
BW_Spec_plus = models.CharField(max_length=255, blank=True, null=True)
Bandwidth = models.CharField(max_length=255, blank=True, null=True)
Bandwidth_num = models.FloatField()
Blocking = models.CharField(max_length=255, blank=True, null=True)
Clear_Aperture = models.CharField(max_length=255, blank=True, null=True)
Description = models.CharField(max_length=255, blank=True, null=True)
Dimensions = models.CharField(max_length=255, blank=True, null=True)
Dimensions_Spec_minus = models.CharField(max_length=255, blank=True, null=True)
Dimensions_Spec_plus = models.CharField(max_length=255, blank=True, null=True)
Flatness = models.CharField(max_length=255, blank=True, null=True)
Item_category = models.CharField(max_length=255, blank=True, null=True)
Item_classification = models.CharField(max_length=255, blank=True, null=True)
MODID = models.CharField(max_length=255, blank=True, null=True)
Minimum_Transmission = models.CharField(max_length=255, blank=True, null=True)
Operating_Temperature = models.CharField(max_length=255, blank=True, null=True)
Parallelism = models.CharField(max_length=255, blank=True, null=True)
RECORDID = models.CharField(max_length=255, blank=True, null=True)
Revision_Date = models.CharField(max_length=255, blank=True, null=True)
Revision_Letter = models.CharField(max_length=255, blank=True, null=True)
Ring_Depth = models.CharField(max_length=255, blank=True, null=True)
Scratch_Dig = models.CharField(max_length=255, blank=True, null=True)
Set_Components = models.TextField()
Special_Specifications = models.CharField(max_length=255, blank=True, null=True)
Special_Specs_A = models.CharField(max_length=255, blank=True, null=True)
Special_Specs_B = models.CharField(max_length=255, blank=True, null=True)
Special_Specs_C = models.CharField(max_length=255, blank=True, null=True)
StdOrResale = models.CharField(max_length=255, blank=True, null=True)
Thickness = models.CharField(max_length=255, blank=True, null=True)
Thickness_Spec_minus = models.CharField(max_length=255, blank=True, null=True)
Thickness_Spec_plus = models.CharField(max_length=255, blank=True, null=True)
URL = models.CharField(max_length=1024, blank=True, null=True)
WL_Spec_minus = models.CharField(max_length=255, blank=True, null=True)
WL_Spec_plus = models.CharField(max_length=255, blank=True, null=True)
Wavelength = models.CharField(max_length=255, blank=True, null=True)
Wavelength_num = models.FloatField()
set_components = models.CharField(max_length=255, blank=True, null=True)
# webqty fields
quantity = models.IntegerField(default=0, blank=True, null=True)
# Pricing/web_all fields
curr_intl_base_price_a_stored = models.CharField(max_length=255, blank=True, null=True)
curr_intl_base_price_b_stored = models.CharField(max_length=255, blank=True, null=True)
curr_domestic_base_price_a_stored = models.CharField(max_length=255, blank=True, null=True)
curr_domestic_base_price_b_stored = models.CharField(max_length=255, blank=True, null=True)
Weight = models.FloatField(default='0.05')
wavelength_range_high = models.CharField(max_length=255, blank=True, null=True)
wavelength_range_low = models.CharField(max_length=255, blank=True, null=True)
blocking_option_1 = models.CharField(max_length=255, blank=True, null=True)
blocking_option_2 = models.CharField(max_length=255, blank=True, null=True)
tx_option_1 = models.CharField(max_length=255, blank=True, null=True)
tx_option_2 = models.CharField(max_length=255, blank=True, null=True)
class Meta:
pass
# class ProductIndex(indexes.SearchIndex, indexes.Indexable):
# pass
class ProductAdmin(admin.ModelAdmin):
list_display = ('part_number', 'category',)
list_filter = ('category',)
search_fields = ('part_number',)
admin.site.register(Product, ProductAdmin)