I have an unexplainable problem involving importing from 3 apps and one python script. Thank you to those who took the time to understand this problem.
Sorry I cannot explain this problem, I tried to make it as simple as possible below. 'acc' has many 'numbers' which has a one-to-one relationship with 'two'. 'python run.py' tries to import from 'numbers' but causes import errors when 'acc' modelchoicefield queryset changes from 'all' to 'filter' ----------------acc/models.py-------------- from django.db import models from django import forms class Group(models.Model): name=models.IntegerField() class User(models.Model): group=models.ForeignKey(Group) class UserForm(forms.ModelForm): group=forms.ModelChoiceField(Group.objects.all()) #causes problem if changed to Group.objects.filter(name='blah') class Meta: model=User ----------------number/models.py------------ from django.db import models from acc.models import User class Number(models.Model): name=models.IntegerField() -------------------two/models.py----------------- from django.db import models from numbers.models import Number class Two(models.Model): number=models.OneToOneField(Number,primary_key=True) #potential problem line ---------------run.py----------------------- #!/usr/bin/env python from django.core.management import setup_environ import settings setup_environ(settings) from numbers.models import Number #######PROBLEM-####### With the above setup, if i execute: python run.py, it should be fine. BUT the problem occurs the moment i change acc.models from: group=forms.ModelChoiceField(Group.objects.all()) #TO# group=forms.ModelChoiceField(Group.objects.filter(name='blah')) The last error it will show is: File "/home/robin/test/toast/two/models.py", line 2, in <module> from numbers.models import Number ImportError: cannot import name Number Thanks a lot, Robin The complete errors are below: Traceback (most recent call last): File "expire_listing.py", line 6, in <module> from numbers.models import Number File "/home/robin/test/toast/numbers/models.py", line 2, in <module> from acc.models import User File "/home/robin/test/toast/acc/models.py", line 11, in <module> class UserForm(forms.ModelForm): File "/home/robin/test/toast/acc/models.py", line 12, in UserForm group=forms.ModelChoiceField(Group.objects.filter(name__in=[0,1])) File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 102, in filter return self.get_query_set().filter(*args, **kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 489, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 507, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1258, in add_q can_reuse=used_aliases) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1133, in add_filter negate=negate, process_extras=process_extras) File "/usr/lib/python2.5/site-packages/django/db/models/sql/ query.py", line 1309, in setup_joins field, model, direct, m2m = opts.get_field_by_name(name) File "/usr/lib/python2.5/site-packages/django/db/models/options.py", line 281, in get_field_by_name cache = self.init_name_map() File "/usr/lib/python2.5/site-packages/django/db/models/options.py", line 311, in init_name_map for f, model in self.get_all_related_m2m_objects_with_model(): File "/usr/lib/python2.5/site-packages/django/db/models/options.py", line 388, in get_all_related_m2m_objects_with_model cache = self._fill_related_many_to_many_cache() File "/usr/lib/python2.5/site-packages/django/db/models/options.py", line 402, in _fill_related_many_to_many_cache for klass in get_models(): File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 136, in get_models self._populate() File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 57, in _populate self.load_app(app_name, True) File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 72, in load_app mod = __import__(app_name, {}, {}, ['models']) File "/home/robin/test/toast/two/models.py", line 2, in <module> from numbers.models import Number ImportError: cannot import name Number --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---