当我尝试在Django中使用“过滤器”方法:
dumpData.objects.filter(bid = True)
我得到以下例外:
ImportError:没有名为Trades的模块
File "XXX\CacheUtil.py", line 141, in loadItems print DumpData.objects.filter(bid = True)
File "XXX\site-packages\django\db\models\manager.py", line 141, in filter
return self.get_query_set().filter(*args, **kwargs)
File "X:\Python27\lib\site-packages\django\db\models\query.py", line 550, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "X:\Python27\lib\site-packages\django\db\models\query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "X:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1194, in add_q
can_reuse=used_aliases, force_having=force_having)
File "X:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1069, in add_filter
negate=negate, process_extras=process_extras)
File "X:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1248, in setup_joins
field, model, direct, m2m = opts.get_field_by_name(name)
File "X:\Python27\lib\site-packages\django\db\models\options.py", line 307, in get_field_by_name
cache = self.init_name_map()
File "X:\Python27\lib\site-packages\django\db\models\options.py", line 337, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "X:\Python27\lib\site-packages\django\db\models\options.py", line 414, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "X:\Python27\lib\site-packages\django\db\models\options.py", line 428, in _fill_related_many_to_many_cache
for klass in get_models():
File "X:\Python27\lib\site-packages\django\db\models\loading.py", line 167, in get_models
self._populate()
File "X:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate
self.load_app(app_name, True)
File "X:\Python27\lib\site-packages\django\db\models\loading.py", line 76, in load_app
app_module = import_module(app_name)
File "X:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named Trades
Trade是我的Django App,位于
下的settings.py中INSTALLED_APPS = (
(...),
'Trades')
DumpData定义为:
class DumpData(models.Model):
orderId = models.BigIntegerField()
typeId = models.BigIntegerField()
price = models.DecimalField(decimal_places=2,max_digits=20)
bid = models.BooleanField()
issued = models.DateField()
dateDumped = models.DateTimeField()
如果我只尝试
dumbData.objects.all()
一切正常,所以它可能不是服务器/数据库问题。 (我也可以毫无例外地保存日期。)
答案 0 :(得分:0)
我没有找到任何关于它的文档,但我建议对应用程序使用小写名称。 另外,试试:
dumpData.objects.filter(bid = True).all()
答案 1 :(得分:0)
好的,我解决了我的问题。 因为它没有起作用的原因是在Project Strukture中,我有:
\src
\PackageNr1
Main.py <-- File where Django was called.
\PackageNr2 <-- Package for the Django Files
\trades <-- Django App
models.py ,
views ...usw
settings.py <-- Django Settings File
manage.py
Witch this Struckture我可以调用“save()”或“object.all()”之类的东西,它运行正常。但对于大多数人来说,它没有用。所以我将我的Django包移到了Main Pakcage中,现在它可以工作了。新的Struckture看起来像这样:
\src
\PackageNr1
\trades <-- The django app
models.py
views ....
Main.py
settings.py <--Django Files
manage.py
这对我来说很好。