在管理/命令中导入我的模型时,我得到了这个回溯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/vagrant/rsspainter/apps/account/management/commands/create_users.py", line 5, in <module>
from models import *
File "/vagrant/rsspainter/apps/account/models.py", line 5, in <module>
class SeoUser(models.Model):
File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/db/models/base.py", line 93, in __new__
kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range
怎么了??Django 管理页面效果很好。
我的模型:
class SeoUser(models.Model):
'''
Model of user.
'''
SEX = (
('M', 'Male'),
('F', 'Female'),
)
THEME_CHOICES = (
('auto', u'Автомобили'),
('tourism', u'Туризм'),
('cooking', u'Готовка'),
('gambling', u'Гэмблинг'),
('games', u'Онлайн игры'),
('business', u'Бизнесс'),
('amusement', u'Развлечения'),
('sports', u'Спорт и здоровье'),
('nyan', u'Животные'),
('quotes', u'Цитатники'),
('humor', u'Юмор'),
('women', u'Женские секреты'),
)
name = models.CharField("Name", max_length=100, blank=False)
surname = models.CharField("Surname",max_length=150, blank=False)
password = models.CharField("Password", max_length=16)
country = models.CharField("Country", max_length=25)
town = models.CharField("Town", max_length=35)
is_real = models.BooleanField("Real user", default=False)
sex = models.CharField("Sex", max_length=1, choices=SEX)
age = models.IntegerField("Age", blank=False)
thematics = models.CharField("Specification", max_length=15, choices=THEME_CHOICES, default='amusement')
def __unicode__(self):
return "%s-%s" % (self.name, self.thematics)
# links to related models
def email_count(self):
return self.email.count()
email_count.short_description = 'Email accounts'
def blog_count(self):
return self.blog.count()
blog_count.short_description = 'Blogs'
def twitter_count(self):
return self.twitter.count()
twitter_count.short_description = 'Twitter accounts'