Django-South内省规则不起作用

Ory*_*and 13 python migration django django-south

我正在使用Django 1.2.3South 0.7.3.

我正在尝试将我的应用程序(命名core)转换为使用Django-South.我有一个我正在使用的自定义模型/字段,名称ImageWithThumbsField.它基本上只是django.db.models.ImageField具有一些属性,如身高,体重等.

虽然./manage.py convert_to_auth core我试图接受南方的冰冻错误.我不明白为什么,我可能会遗漏一些东西......

我使用的是简单的自定义模型:

from django.db.models import ImageField

class ImageWithThumbsField(ImageField):
    def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, sizes=None, **kwargs):
        self.verbose_name=verbose_name
        self.name=name
        self.width_field=width_field
        self.height_field=height_field
        self.sizes = sizes
        super(ImageField, self).__init__(**kwargs)
Run Code Online (Sandbox Code Playgroud)

这是我的内省规则,我将其添加到我的顶部models.py:

from south.modelsinspector import add_introspection_rules
from lib.thumbs import ImageWithThumbsField

add_introspection_rules(
    [
        (
            (ImageWithThumbsField, ),
            [],
            {
                "verbose_name": ["verbose_name", {"default": None}],
                "name":         ["name",         {"default": None}],
                "width_field":  ["width_field",  {"default": None}],
                "height_field": ["height_field", {"default": None}],
                "sizes":        ["sizes",        {"default": None}],
            },
        ),
    ],
    ["^core/.fields/.ImageWithThumbsField",])
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误:

! Cannot freeze field 'core.additionalmaterialphoto.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.photo'
! (this field has class lib.thumbs.ImageWithThumbsField)
! Cannot freeze field 'core.material.formulaimage'
! (this field has class lib.thumbs.ImageWithThumbsField)

! 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
Run Code Online (Sandbox Code Playgroud)

有人知道为什么吗?我究竟做错了什么?

Ory*_*and 17

我知道了!:)

我改变了这个: ["^core/.fields/.ImageWithThumbsField",]

对此: ["^lib\.thumbs\.ImageWithThumbsField",]

这整行是Django字段类型的python路径的正则表达式(再读一遍,长句).

偶然发现了ImageWithThumbsField在路径中声明的字段名称lib.thumbs.我给了他一条错误的道路,所以当绊倒在这片土地上时,南方仍然不知道该怎么办.

一旦我给了他正确的路径,它知道如何处理该领域.

  • 可能这个问题太具体了,不能引起太多关注,但只知道你救了我的一天.我需要几个小时才能达到解决方案,这完全可以解决问题.正如旁注,对我有用的是["^ myapp.thumbs.ImageWithThumbsField",]因为我的thumbs.py在myapp目录中.干杯! (4认同)
  • 它应该是`["^ lib\.thumbs\.ImageWithThumbsField",])`.点"." 在正则表达式中有特定含义,所以你必须用反斜杠转义它. (3认同)