Creating Dynamic Models

2012-06-11 Thread Karandeep Nagra
Hi, New user to Django. I have a class 'Server' and I want to set up my Django site so that when a server is added through the admin interface, an additional model along with its admin.ModelAdmin class are added. So say a server 'Crushinator' is added to the database of servers. At its creat

Re: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
Hi Matthias , Thank you, I went for option 1 and it works perfectly! Funny, the add_to_class function basically does "setattr(cls, name, value)". So I had the right solution, only you have to do this after class creation, not inside its __init__ function. Good to know, will blog about this :) Ag

Re: Creating dynamic models?

2009-11-26 Thread Matthias Kestenholz
On Thu, Nov 26, 2009 at 9:56 AM, Kevin Renskers wrote: > 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,

Re: Creating dynamic models?

2009-11-26 Thread Kevin Renskers
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 wrote: > Hi all, > > In my Django project I want to h

Creating dynamic models?

2009-11-24 Thread Kevin Renskers
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: