Re: Getting a class using a variable name.

2011-09-11 Thread pbzRPA
Ok, I found a way. I don't know if it's the best way but it works :) return getattr(__import__(module_name, fromlist = [class_name]), class_name) Thanks for the help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

Re: Getting a class using a variable name.

2011-09-11 Thread pbzRPA
Hi Martin, Thanks for the tip. The thing is that I store my class names in the database. So class B(models.Mode): form_class = models.CharField(...) def get_form_class(self): return ..(self.form_class) <- this is where I need to some how get the class object from a different

Re: Getting a class using a variable name.

2011-09-11 Thread Martin Tiršel
Hi, you can do the import here to prevent circular import: class B(models.Model): def get_a_class(self): from test_a import A return A Martin On Sun, 11 Sep 2011 16:49:22 +0200, pbzRPA wrote: Hi, I have been struggling with this for a while now and I can't seem to find

Re: Getting a class using a variable name.

2011-09-11 Thread pbzRPA
I should add that in the B class function get_a_class I only have a variable name "A" -- 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

Getting a class using a variable name.

2011-09-11 Thread pbzRPA
Hi, I have been struggling with this for a while now and I can't seem to find a way of returning a class object from a different module without importing it. Say I have two files: test_a.py class A(models.Model): pass test_b.py class B(models.Model): def get_a_class(se