来自导入应用程序的模型的 Django 固定装置(如 django-allauth)

标签 django json django-allauth django-fixtures

我知道可以为我自己的模型创建像 initial_data.json 这样的夹具文件。我想为导入的 django-allauth 应用程序创建和使用的表创建类似的文件。

我试过:

[
    {
        "model":"allauth.socialaccount.models.SocialApp",
        "pk":1,
        "fields":{
            "id":"1",
            "provider":"facebook",
            "name":"facebook",
            "client_id":"0011223344556677",
            "key":"",
            "secret":"012345678901234567890123456"
        }
    }
]

然而它以错误结束:

python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
DeserializationError: Problem installing fixture 'initial_data.json': 
  Invalid model identifier: 'allauth.socialaccount.models.SocialApp'

最佳答案

我发现 here 模型 django.contrib.sites.models.Site 中的表可以使用

[
  {
    "model": "sites.site", 
    "pk": 1, 
    "fields": {
      "domain": "myproject.mydomain.com", 
      "name": "My Project"
    }
  }
]

所以模型 allauth.socialaccount.models.SocialApp 可能可以通过填充:

[
    {
        "model":"socialaccount.socialapp",
        "pk":1,
        "fields":{
            "id":"1",
            "provider":"facebook",
            "name":"facebook",
            "client_id":"0011223344556677",
            "key":"",
            "secret":"012345678901234567890123456"
        }
    }
]

关于来自导入应用程序的模型的 Django 固定装置(如 django-allauth),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020791/

相关文章:

python - Python xlrd (Python Excel) 和 Amazon S3 的 IOError

django - 为什么 CeleryCAM 不能与 Amazon SQS 一起使用?

javascript - ASP.NET MVC JSON Entity Framework - 保存数据

在 SSL 中运行的 django-allauth

django-allauth - 覆盖默认注册表单

django - 如何自定义 Django 的 Flatpage 以在管理员的更改列表页面上显示新字段?

python - GenericAPIView 中的嵌套操作

json - 如何获取json字段?

ios - 如何在一次查询中检索多个数据 Firebase

python - django allauth 电子邮件登录 - 总是错误