Reputation: 2680
I want to custom validate a Page
object. A Project
has many Page
's.
To validate the Page
object I need to get a reference to the Project
object through its pk
in Page
.
Need to compare start_date
field in Project
to start_date
field in Page
:
class PageForm(ModelForm):
class Meta:
model = Page
def clean_start_date(self):
# need to get "page.project.start_date" somehow.
Upvotes: 0
Views: 569
Reputation: 62908
Use the instance
property:
class PageForm(ModelForm):
class Meta:
model = Page
def clean_start_date(self):
project_start_date = self.instance.project.start_date
Upvotes: 4