make_option(
'--file',
action='store',
dest='in_file',
help="File to process"),
make_option(
'--filter',
action='store',
dest='filter',
help="Filter by a store object")
def run(self, *args, **kwargs):
with open(kwargs['in_file']) as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
filter_store = row[0] #123123
update_store = row[1]
Store.objects.filter(**kwargs['filter'] = filter_store).update(**kwargs['update'] = update_store)
Run Code Online (Sandbox Code Playgroud)
这不包括完整的代码^
我试图用存储ID过滤数据库我通过存储的kwargs传递,但得到语法错误.
Store.objects.filter(**kwargs['filter'] = filter_store)
Run Code Online (Sandbox Code Playgroud)
基本上**kwargs['filter']这里有"id"值并且filter_store有商店ID.它应该执行以下操作**kwargs:
Store.objects.filter(id = 4334225)
Run Code Online (Sandbox Code Playgroud)