tags:

views:

24

answers:

2

I have a ModelFormA for ModelA, which has a one-one relationship with ModelB and foreign-key relationship with ModelC.

Inside ModelFormA, I can access attributes of the current ModelA instance via self.cleaned_data["colA-1"]. How would I access attributes of ModelB or ModelC?

A: 

self.cleaned_data["foreign_key_column"] actually returns an instance of the related model. Same goes for one-to-one relationship

theactiveactor
+1  A: 

If you want the current values of the object, rather than the values submitted by the form, you actually need to use self.instance. You can then do self.instance.myforeignkey or whatever you need to follow relationships.

Daniel Roseman