Configuring a custom JSONField to be treated like a django.db.models.fields.TextField

54 views
Skip to first unread message

Michael Jones

unread,
Oct 9, 2014, 1:21:00 PM10/9/14
to south...@googlegroups.com
Hi,

My app is using a custom field that subclasses the JSONField provided by this project:


Unfortunately for reasons beyond my experience, when south does a data-migration with this simple rule setup:

    from south.modelsinspector import add_introspection_rules
    add_introspection_rules([], ["^top\.modelfields\.DescriptionField"])

The json data is escaped inappropriately. I think this is to do with the JSONField implementation and how it figures out when to encode & decode the json data. 

I have found a work around which is to generate the migration script and then edit the field entries like so:

-            'description': ('top.modelfields.DescriptionField', [], {'default': '[]', 'blank': 'True'}),
+            # Tell south that the description field is actually just a text field
+            'description': ('django.db.models.fields.TextField', [], {'default': '[]', 'blank': 'True'}),

Unfortunately, whilst this works, I have to remember to do and as a recent experience as proven, I don't always do that.

Is there a way I can tell South to treat the field as a TextField for these migrations? Or would there be a better way to approach the situation? Ideally the JSONField implementation would be fixed, but I don't understand how to do that currently.

Any help would be much appreciated,
Michael

Andrew Godwin

unread,
Oct 9, 2014, 1:58:18 PM10/9/14
to south...@googlegroups.com
You should implement the south_field_triple method on the custom class and make it return the TextField path as the first argument. Docs here: http://south.readthedocs.org/en/latest/customfields.html#south-field-triple

Andrew

--
You received this message because you are subscribed to the Google Groups "South Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to south-users...@googlegroups.com.
To post to this group, send email to south...@googlegroups.com.
Visit this group at http://groups.google.com/group/south-users.
For more options, visit https://groups.google.com/d/optout.

Michael Jones

unread,
Oct 10, 2014, 4:23:49 AM10/10/14
to south...@googlegroups.com
Fantastic, thank you and sorry for not realising that was part of the docs. I did try, but I apparently failed.

Much appreciated,
Michael
Reply all
Reply to author
Forward
0 new messages