小编Sim*_*ris的帖子

Django 继承模型的 JSON 序列化

我有以下 Django 模型

class ConfigurationItem(models.Model):

    path = models.CharField('Path', max_length=1024)
    name = models.CharField('Name', max_length=1024, blank=True)
    description = models.CharField('Description', max_length=1024, blank=True)
    active = models.BooleanField('Active', default=True)
    is_leaf = models.BooleanField('Is a Leaf item', default=True)

class Location(ConfigurationItem):

    address = models.CharField(max_length=1024, blank=True)
    phoneNumber = models.CharField(max_length=255, blank=True)
    url = models.URLField(blank=True)
    read_acl = models.ManyToManyField(Group, default=None)
    write_acl = models.ManyToManyField(Group, default=None)
    alert_group= models.EmailField(blank=True)
Run Code Online (Sandbox Code Playgroud)

如果有帮助,完整的模型文件在这里

您可以看到 Company 是 ConfigurationItem 的子类。

我正在尝试使用 django.core.serializers.serializer 或 WadofStuff 序列化器来使用 JSON 序列化。

两个序列化器给我同样的问题......

>>> from cmdb.models import *
>>> from django.core import serializers
>>> …
Run Code Online (Sandbox Code Playgroud)

python django json jsonserializer

4
推荐指数
1
解决办法
2246
查看次数

标签 统计

django ×1

json ×1

jsonserializer ×1

python ×1