Django Form Validation Not Triggering on Nested Model Forms with Inline Admin
Quick question that's been bugging me - I'm currently facing an issue where validation on nested model forms within the Django admin is not being triggered as expected. I have a parent model `Author` and a related inline model `Book`. The `Book` model has a `title` field that is required. However, when I try to submit the form without providing a title, the validation error doesn't appear. Instead, the form just saves the author without the book, which should not happen. Here's the relevant code: ```python from django.db import models from django.contrib import admin class Author(models.Model): name = models.CharField(max_length=100) class Book(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books') title = models.CharField(max_length=200) class BookInline(admin.TabularInline): model = Book extra = 1 class AuthorAdmin(admin.ModelAdmin): inlines = [BookInline] admin.site.register(Author, AuthorAdmin) ``` I expect that if the `title` field is left blank, an error message should be displayed, preventing the form from being saved. However, it's behaving as if the book instance is optional. I've tried implementing custom validation methods in the `BookInline` class, but they don't seem to be invoked during the save process. Here's what I attempted: ```python class BookInline(admin.TabularInline): model = Book extra = 1 def clean(self): super().clean() for form in self.forms: if not form.cleaned_data.get('title'): raise ValidationError('Title is required for each book.') ``` Yet, I still see no effect. I've also checked the `settings.py` to ensure that `USE_TZ = True` and `TIME_ZONE = 'UTC'`, but that shouldn't affect form validation right? Has anyone else encountered this issue or has suggestions on how to enforce required fields on inline model forms in Django admin? I'm using Django 3.2.6 and have ensured all packages are up to date. Any insights or recommendations would be greatly appreciated! I'm working on a web app that needs to handle this. Any help would be greatly appreciated!