我正在测试Django中的一个小管理脚本,用表格中的选项列表中的值填充表格。这在一个开发环境中完全正常,但是当我在另一个开发环境中尝试它时,它会失败:
ob.objects.create(类型= R [0])
AttributeError:'Manager'对象没有属性'objects'
据我所知,virtualenvs是一样的。我正在使用git进行同步,它认为代码是相同的。 可能有什么不同意味着它适用于一个开发环境而不是另一个环境?
下面的脚本:
:::python
class Command(BaseCommand):
help = 'Create Initial Resources'
def add_arguments(self, parser):
pass
def handle(self, *args, **options):
self.stdout.write('Filling Resource Table')
out = ''
ob = Resource.objects
for r in Resource.Label_Choices:
if not ob.filter(type=r[0]):
ob.objects.create(type=r[0])
out = out + ":" + str(r[0])
else:
out = out + ":" + '*'
self.stdout.write(self.style.SUCCESS(out))
答案 0 :(得分:1)
此行def handle(self, *args, **options):
self.stdout.write('Filling Resource Table')
out = ''
ob = Resource.objects.all() # Edit here
for r in Resource.Label_Choices:
if not ob.filter(type=r[0]):
Resource.objects.create(type=r[0]) # Edit here
out = out + ":" + str(r[0])
else:
out = out + ":" + '*'
self.stdout.write(self.style.SUCCESS(out))
可能被视为您的错误的关键
UIView.appearance().semanticContentAttribute = .forceRightToLeft