How add custom field dynamicly? I'm trying that, but the field won't insert into database when I sync db:
#It use as register(MyModel)
def register(model, attr="my_attr"):
if model in registry:
raise AlreadyRegistered(
_('The model %s has already been registered.') % model.__name__)
registry.append(model)
setattr(model, attr, MyField())
MyField().contribute_to_class(model, attr)
#MyField.contribute_to_class
def contribute_to_class(self, cls, name):
super(MyField, self).contribute_to_class(cls, name)
setattr(cls, self.name, self)
cls.add_to_class('%s_manager' % name, MyDescriptor())
signals.post_save.connect(self._save, cls, True)