Just a small update: the DynamicModels way as described on the wiki doesn't work (it also says that it only works in Django 0.96, so yeah..).
If anyone has any idea how to do this, I would be very thankful! On Nov 24, 2:35 pm, Kevin Renskers <i...@bolhoed.net> wrote: > Hi all, > > In my Django project I want to have a model that is dynamically > created. I tried using the __init__ function for this, something like > so: > > fields = ['field_a', 'field_b', 'field_c'] > > class MyModel(models.Model): > def __init__(self, *args, **kwargs): > for field in fields: > setattr(self, field, models.DecimalField(decimal_places=4, > max_digits=10)) > > Sadly, this doesn't work. The columns don't get created when you run > the syncdb command, and even something like > MyModel._meta.get_all_field_names() doesn't return the dynamic fields. > > So, is there a way I can create a "dynamic" model? I did come > acrosshttp://code.djangoproject.com/wiki/DynamicModelsbut I don't really > get that. It looks so much different then normal models, it seems like > I would loose a lot of functionality or would have to change a lot of > code somewhere else in my application? > > Hopefully there is an easy way to do this :) > > Cheers, > Kevin -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.