Modify ↓
Ticket #422 (closed defect: invalid)
Custom Field that defines an __init__ without arguments
| Reported by: | anonymous | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.7.1 |
| Component: | commands | Version: | 0.7 |
| Keywords: | Cc: |
Description
I have a custom field that store the last modification time of the model in seconds since the Epoch.
This field defines a constructor without arguments, and all field configuration is set when the super class is called.
When I try to migrate the models using this field, I have an error :
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/South-0.7-py2.5.egg/south/orm.py", line 237, in eval_in_context
return eval(code, globals(), fake_locals)
File "<string>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'default'
Here is the custom field definition:
class VersionField(models.IntegerField):
def __init__(self):
models.IntegerField.__init__(self, blank=False, default=0)
def pre_save(self, model_instance, add):
value = int(math.floor(time.time()))
setattr(model_instance, self.attname, value)
return value
And I tried these two ways to declare the field:
add_introspection_rules([], ['^foo\.%s' % VersionField.__name__, ])
add_introspection_rules([([VersionField, ], [], {}, ), ], ['^foo\.%s' % VersionField.__name__, ])
Should I add an *args, kwargs to the constructor event if they are not used to make it work ?
Thanks
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

Ah, yes, I see the problem. You'll need to write new introspection rules that _remove_ the keyword arguments, as your field has inherited some from Field.
The ignore_if option excludes the field from the frozen version if the attribute it's pointing to coerces to true, so a rule like this would be enough to stop it putting default in:
"default": ["default", {"ignore_if": "name"}](This works because fields always have a name).
Also, in future, I'd appreciate it if individual help went to the mailing list - it's kind of hard to categorise it here into a bug or feature request!