我需要将一个整数参数传递给Django中的基本命令.例如,如果我的代码是
from django.core.management import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options, number_argument):
square = number_argument ** 2
print square
Run Code Online (Sandbox Code Playgroud)
我想说python manage.py square_command 4并让它返回16.有没有办法可以通过终端将参数传递给我想要运行的命令?
我正在运行Django 1.7.我的项目文件树是这样的:
/project/app/fixtures/initial_data.json
/project/app/settings.py
Run Code Online (Sandbox Code Playgroud)
我知道我可以运行python manage.py loaddata app/fixtures/initial_data.json命令来填充我的数据库,但我想在python manage.py migrate运行时自动加载它.我的设置包括:
FIXTURE_DIRS = (
os.path.join(BASE_DIR, '/app/fixtures/'),
)
Run Code Online (Sandbox Code Playgroud)
但是在运行迁移时不应用夹具.什么似乎是问题?
我想提高效率,但我无法弄清楚如何将其转化为python列表理解.
coupons = []
for source in sources:
for coupon in source:
if coupon.code_used not in coupons:
coupons.append(coupon.code_used)
Run Code Online (Sandbox Code Playgroud)