7

I have a main form that has an inline-form. Is it possible to access the main form's cleaned_data from the inline-form's clean function?

Here is why I am asking.

The main form has a field to define if a property is for-sale or to lease. The inline form then displays either a sale price field or fields for the lease amount and deposit. I am trying to validate that if the property is for sale, then the lease and deposit fields should be empty.

I can do this in a view for the frontend interface, but is it possible to be done in forms.py for both the frontend and the admin?

bmeyer71
  • 362
  • 3
  • 10
  • 23

1 Answers1

8

No, these forms are separate objects and are completely unaware of each other. But you are providing same data to all forms, so you should be able to check fields from self.data.

int_ua
  • 1,646
  • 2
  • 18
  • 32
ilvar
  • 5,718
  • 1
  • 20
  • 17
  • Thank you for your reply. I'm not sure I am following. When I look at the cleaned_data for the inline form, I am only seeing the data for that form. How should I access the fields from the parent form? – bmeyer71 Apr 17 '12 at 17:50
  • 1
    Use `self.data`, not `self.cleaned_data` – ilvar Apr 18 '12 at 04:06
  • 1
    Excellent. I did not know that was available. I've only ever used cleaned_data. Thank you for your help. – bmeyer71 Apr 18 '12 at 18:45
  • 1
    You should not use `form.data` everywhere because it is raw data and it should be checked and cleaned but in cases like "check if the value exists" or "check if the value is equal to something" it works fine. – ilvar Apr 19 '12 at 04:24
  • I wasn't going to use it for all data just to check for a value. cleaned_data will be what is used for the form's data. Thanks again. – bmeyer71 Apr 21 '12 at 15:29