如何创建接受两个不同dict键和值并能够导入数据的模型字段?

2024-09-30 06:23:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Django的新手。我开始了一个收集书籍数据的小项目——从谷歌图书api(GoogleBooksAPI)开始,并有可能手动添加新的帖子

我不知道如何在JSON中处理字典,我指的是“行业标识符”:

"publisher": "Random House Digital, Inc.",
  "publishedDate": "2005-11-15",
  "description": "\"Here is the story behind one of the most remarkable Internet
  successes of our time. Based on scrupulous research and extraordinary access
  to Google, ...",
  "industryIdentifiers": [
   {
    "type": "ISBN_10",
    "identifier": "055380457X"
   },
   {
    "type": "ISBN_13",
    "identifier": "9780553804577"
   }
  ],

如何使手动输入和从API导入兼容

我应该在“行业标识”中选择哪种字段输入 ISBN_10和ISBN_13及其标识符

class Books(models.Model):
    title = models.CharField(max_length=250)
    authors = models.CharField(max_length=250)
    publishedDate = models.DateField(blank=True, null=True)
    industryIdentifiers = 
    pageCount = models.IntegerField(blank=True, null=True)
    imageLinks = models.URLField(blank=True, null=True)
    language = models.CharField(max_length=5)

Tags: ofthetruemodels标识符手动nulllength

热门问题