Hi,

I would like to get the class name from a relation name (OneToOne)

For example :

class ModelA(models.Model):
    label = models.CharField(max_length=255)

class ModelB(models.Model):
    a = models.OneToOneField(ModelA)

class ModelC(models.Model):
    a = models.OneToOneField(ModelA)

If I have :
a = ModelA(pk=1)

Then the relation to ModelB object from a is
a.modelb

I want to get the class of the object a.modelb (ie ModelB) without
instanciating a ModelA. Is there a clever way to get it from the model
definition ? or do I have to check every case like :
def get_class_from_ModelA_relation(type):
    if type == 'modelb':
        return 'ModelB'
    if type == 'modelc':
        return 'ModelC'
    else:
        return None

Thanks in advance !

-- 
Grégoire

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to