Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 如何在字典中保存多个元素?_Django_Python 3.x - Fatal编程技术网

Django 如何在字典中保存多个元素?

Django 如何在字典中保存多个元素?,django,python-3.x,Django,Python 3.x,假设我有一个这样的模型: class Post(model.Model) name = model.CharField(max_lenght) description= model.CharField() 我有这本字典 d = {'name':'jerry', 'description':'all} 保存目录: p = Post(**d) p.save() 但如果我有这句话: d = {'name':'jerry', 'description':'all, 'name1': '

假设我有一个这样的模型:

class Post(model.Model)
   name = model.CharField(max_lenght)
   description= model.CharField()
我有这本字典

d = {'name':'jerry', 'description':'all}
保存目录:

p = Post(**d)
p.save()
但如果我有这句话:

d = {'name':'jerry', 'description':'all, 'name1': 'lucy', 'description1': 'tr'}
我可以在Post中保存元素吗:

Name    Description
jerry     all
lucy      tr

看起来你缺少了一些引语。。。既然如此,为什么要将
名称
存储在
name1
中,而不是列出有效的词汇表?如果其中一个字段是例如
name1
?那么这将导致歧义。通常最好是用一系列字典来解决这个问题,每个字典都有真实的名字。所以字典列表{'name':['jerry','luc'],'description'['add','fil']}