13

I'm using Django 1.2.3 and South 0.7.3.

I am trying to convert my app (named core) to use Django-South. I have a custom model/field that I'm using, named ImageWithThumbsField. It's basically just the ol' django.db.models.ImageField with some attributes such as height, weight, etc.

While trying to ./manage.py convert_to_auth core I receieve South's freezing errors. I have no idea why, I'm Probably missing something...

I am using a simple custom Model:

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)

And this is my introspection rule, which I add to the top of my 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",])

This is the errors I receieve:

! 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

Does anybody know why? What am I doing wrong?

Ory Band
  • 14,716
  • 14
  • 59
  • 66

1 Answers1

17

I got it! :)

I changed this: ["^core/.fields/.ImageWithThumbsField",]

To this: ["^lib\.thumbs\.ImageWithThumbsField",]

This whole line is a regular-expression of python paths of Django field types (read this again, long sentence).

South stumbled upon a field name ImageWithThumbsField that was declared in the path lib.thumbs. I gave him a wrong path, so South still didn't know what to do when stumbling upon this field.

Once I gave him the correct path, it knew how to handle the field once he got to it.

Natim
  • 17,274
  • 23
  • 92
  • 150
Ory Band
  • 14,716
  • 14
  • 59
  • 66
  • Can't accept the answer yet, http://StackOverflow.com says I need to wait 2 days before doing so. – Ory Band Jan 17 '11 at 17:50
  • 4
    Probably this question is too specific for it to get much attention, but just know you saved my day. I'd take hours to reach the solution, and this totally did the trick. Just as a sidenote, what worked for me was ["^myapp.thumbs.ImageWithThumbsField",] as my thumbs.py is inside the myapp dir. Cheers! – rlafuente May 03 '11 at 23:32
  • 3
    It should actually be `["^lib\.thumbs\.ImageWithThumbsField",])`. The dot "." has a particular meaning in regular expressions so you have to escape it with a backslash. – exfizik Dec 12 '11 at 04:25
  • i used @exfizik format and it works. the important thing is to get the correct FULL path! thanks. – Yogev Shelly Apr 04 '12 at 17:39