Russell Keith-Magee wrote: > On 1/20/07, Christian Joergensen <[EMAIL PROTECTED]> wrote: >> I suspect there is some django magic happening behind the scenes, and >> maybe the setattr trick is not at all possible. Can anyone shed some >> light on this? > > Yes - the model class has a metaclass that is used to convert the > member fields in the model declaration and turns them into attributes.
Thank you, this was exactly the pointer i needed. If anyone in the future encounters a similar problem, my solution was: MyModel.add_to_class('foo', models.IntegerField()) Instead of: setattr(MyModel, 'foo', models.IntegerField()) This doesn't seem to cause any problems (yet!). > It's not 'magic' - just python metaclasses - and it's call contained > in django.db.models.base In my book of python, this still count as magic ;-) Regards, -- Christian Joergensen | Linux, programming or web consultancy http://www.razor.dk | Visit us at: http://www.gmta.info
signature.asc
Description: OpenPGP digital signature