jorgebastida / django-dajax

Easy to use library to create asynchronous presentation logic with django and dajaxice
http://dajaxproject.com/
BSD 3-Clause "New" or "Revised" License
346 stars 99 forks source link

DajaxiceFinder fails collectstatic #68

Open yeruizhi opened 11 years ago

yeruizhi commented 11 years ago

I installed dajaxice into django project. When i run the web using manage.py runserver, all goes well. Now I try to deploy it with apache/wsgi. When I run manage.py collectstatic, error occur:

ImportError: cannot import name Bag

where Bag is one model within my app.

I tried manage.py shell then import Bag, i works well.

And I tried comment out 'DajaxiceFinder ' from settings.py, collectstatic finished normally.

Could any one help me out?

The full stack of ImportError:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 255, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 164, in handle_noargs
    collected = self.collect()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
    handler(path, prefixed_path, storage)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 285, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 224, in delete_file
    source_last_modified = source_storage.modified_time(path)
  File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 277, in modified_time
    return datetime.fromtimestamp(os.path.getmtime(self.path(name)))
  File "/usr/local/lib/python2.7/dist-packages/dajaxice/finders.py", line 55, in path
    path = self.get_or_create_file(name)
  File "/usr/local/lib/python2.7/dist-packages/dajaxice/finders.py", line 21, in get_or_create_file
    data = getattr(self, self.files[path])()
  File "/usr/local/lib/python2.7/dist-packages/dajaxice/finders.py", line 68, in dajaxice_core_js
    dajaxice_autodiscover()
  File "/usr/local/lib/python2.7/dist-packages/dajaxice/core/Dajaxice.py", line 135, in dajaxice_autodiscover
    import_module("%s.ajax" % app)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/emini/project/emini/trunk/emini/repairment/ajax.py", line 4, in <module>
    from emini.repairment.models import Bag
  File "/home/emini/project/emini/trunk/emini/repairment/models.py", line 9, in <module>
    class Bag(models.Model):
  File "/home/emini/project/emini/trunk/emini/repairment/models.py", line 90, in Bag
    shop_id                 = models.IntegerField(default=0, db_index=True, choices=DataConfig.get_valid_conf_as_choices_by_group(DataConfig.GROUP_NAME_SHOP), verbose_name="店铺")
  File "/home/emini/project/emini/trunk/emini/sysconfig/models.py", line 62, in get_valid_conf_as_choices_by_group
    data_configs = cls.objects.filter(group_name=group_name, enabled=True).order_by('-id')
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 155, in filter
    return self.get_query_set().filter(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 669, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 687, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1271, in add_q
    can_reuse=used_aliases, force_having=force_having)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1139, in add_filter
    process_extras=process_extras)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1325, in setup_joins
    field, model, direct, m2m = opts.get_field_by_name(name)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 351, in get_field_by_name
    cache = self.init_name_map()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 380, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 469, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 483, in _fill_related_many_to_many_cache
    for klass in get_models(only_installed=False):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 197, in get_models
    self._populate()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/emini/project/emini/trunk/emini/express/models.py", line 6, in <module>
    from emini.repairment.models import Bag
ImportError: cannot import name Bag

Enviroment:

Django==1.5.4
django-dajaxice==0.5.5
yeruizhi commented 11 years ago

I try to delete the import Bag from express/models.py, then collectstatic successed.

Structure of my apps:

    emini
        express
            models.py
        repairment
            models.py

in emini.express.models:

from emini.repairment.models import Bag

class Package(models.Model):
    foo = models.CharField(max_length=20)

class BagPackageLink(models.Model):
    bag = models.ForeignKey(Bag)
    package = models.ForeignKey(Package)

    class Meta:
        unique_together = (("bag", "package"),)

in emini.repairment.models

class Bag(models.Model):
    foo = models.CharField(max_length=20)

Am i messing up with 'overlap import'? But why the runserver and shell can import Bag model?