【问题标题】:django-eav and southdjango-eav 和南
【发布时间】:2011-09-15 16:10:27
【问题描述】:

我正在开始一个新的 django 项目,并且像往常一样,我将安装的应用程序放在南方。

然后我需要某种 eav 来在模型中存储一些字段,然后我找到了一个完全符合我要求的应用程序,那就是 django-eav (https://github.com/mvpdev/django-eav)

但现在我面临一个问题,因为南抱怨不知道如何使用 django-eav。

! Cannot freeze field 'eav.attribute.slug'
! (this field has class eav.fields.EavSlugField)
! Cannot freeze field 'eav.attribute.datatype'
! (this field has class eav.fields.EavDatatypeField)

! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork

我正在阅读这个http://south.aeracode.org/docs/customfields.html,并且我正在尝试在不放弃这两个项目中的任何一个的情况下解决这个问题。

有人可以帮助我吗? 谢谢

【问题讨论】:

    标签: python django entity-attribute-value django-south


    【解决方案1】:

    我找到的最佳答案来自http://south.aeracode.org/docs/settings.html#setting-south-migration-modules

    建议您在 settings.py 中设置添加 SOUTH_MIGRATION_MODULES 字典,并将该应用映射到不存在的模块

    SOUTH_MIGRATION_MODULES = {
        'eav': 'ignore',
    }
    

    【讨论】:

    • 也许这是一个更好的解决方案。
    【解决方案2】:

    查看 github 似乎 django-eav 的开发并不活跃。如果它按您的意愿工作并且您不希望更改其数据模型,则无需对其应用 South。 South 可以很好地管理一些应用程序而不是其他应用程序。

    一定要在您正在构建和修改的应用程序上使用 South。但是对于一个稳定的库,我很少打扰。

    【讨论】:

    • 但是 eav 对我的模型很紧。
    • 它通过 GenericForeignKey 解耦。只要模型的主键和名称不变,您就无需担心。您可以根据自己的喜好在模型上添加和删除字段。如果要重命名模型或更改自己模型中的 PK,则必须执行包含 EAV 表的精美数据迁移。如果没有 South 管理 eav 应用程序,仍然有可能,但很棘手。南方管理 EAV 会很棘手。
    • 是的,我同意你的看法。我没有添加 eav 和其他第三方应用程序。谢谢你的建议
    【解决方案3】:

    我想我找到了一种可能的解决方案。

    http://south.aeracode.org/docs/customfields.html#field-name-patterns

    我把这个放在我的模型旁边:

    from south.modelsinspector import add_ignored_fields
    add_ignored_fields(["^eav\.fields\.EavDatatypeField"])
    add_ignored_fields(["^eav\.fields\.EavSlugField"])
    

    现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-28
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 2020-02-11
      • 1970-01-01
      相关资源
      最近更新 更多