On Mon, 2007-06-04 at 18:36 -0400, Lic. José M. Rodriguez Bacallao wrote: > hi people, I want to do a little thing, I want to add fields > dynamically to a model so when I run python manage.py syncdb, > those fields get added to the database table, for example: > > def common_attrs(cls, common): > attrs = dir(common) > for attr in attrs: > if isinstance( getattr(common, attr), models.Field ): > setattr( cls, attr, getattr(common, attr) ) > return cls > > class Content: > title = models.CharField( maxlength = 50 ) > description = models.CharField( maxlength = 100 ) > created_by = models.ForeignKey( User ) > creation_date = models.DateTimeField( auto_now_add = True ) > pub_date = models.DateTimeField() > exp_date = models.DateTimeField() > > class News(Content, models.Model): > text = models.TextField() > News = common_attrs(News, Content) > > but when I run python manage.py syncdb or sql ..., those fields never > get added to the database table, anyone could help me?
See http://code.djangoproject.com/wiki/DynamicModels for one approach. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---