I have four models with the relationships
Model PagetTemplate(models.Model):
pass
Model TextKey(models.Model):
page_template = models.ForeignKey(PageTemplate, related_name='text_keys')
Model Page(models.Model):
page_template = models.ForeignKey(Pagetemplate, related_name='pages')
Model Text(models.Model):
key = models.ForeignKey(TextKey, related_name='text_fields')
page = models.ForeignKey(Page, related_name='text_fields')
the relation is like this:
PageTemplate
/\
/ \
/ \
TextKey Page
\ /
\ /
\/
Text
In the validation for page (In the clean
method), I check that [key for key in page.page_template.text_keys] and [text_field.key for text_field in page.text_fields]
match up so that all text keys are filled in my a text. The problem I am having is that at the time the clean
is called, page.text_fields
is empty. The admin code looks like.
class TextInline(admin.StackedInline):
model = Text
extra = 0
class PageAdmin(DebugModelAdmin):
inlines = [TextInline]
admin.site.register(Page, PageAdmin)
I wrapped admin.ModelAdmin
in a logging class and know that I have the information I need when ModelAdmin.add_view
is called but is overriding this the right thing to do or is there some option/method that would be better to override that I'm missing?