我正在使用django-nested-inlines在 admin 中为这三个模型提供嵌套内联:
class Venue(models.Model):
name = models.CharField(max_length=100)
class VenueBookingSetting(models.Model):
venue = models.ForeignKey(Venue)
name = models.CharField(max_length=100, default='')
use_date_range = models.BooleanField(default=False)
use_valid_days = models.BooleanField(default=False)
days_in_advance = models.SmallIntegerField(default=DEFAULT_DIA)
max_covers = models.SmallIntegerField(default=0, blank=True)
active = models.BooleanField(default=False)
class VenueValidBookingDays(models.Model):
booking_setting = models.ForeignKey(VenueBookingSetting)
sunday = models.BooleanField(default=True)
monday = models.BooleanField(default=True)
tuesday = models.BooleanField(default=True)
wednesday = models.BooleanField(default=True)
thursday = models.BooleanField(default=True)
friday = models.BooleanField(default=True)
saturday = models.BooleanField(default=True)
这是我的 Venue 管理员设置:
class VenueBookingValidDaysInline(NestedTabularInline):
model = VenueBookingValidDays
class VenueBookingSettingInline(NestedTabularInline):
model = VenueBookingSetting
inlines = [VenueBookingValidDaysInline,]
class VenueAdmin(NestedModelAdmin):
inlines = [VenueBookingSettingInline,]
我遇到的问题是在不填写父预订设置的情况下添加预订天数时在哪里捕获 IntegrityError?我的意思是我取消选中一些有效日期,但不更改任何父预订设置项目。谁能告诉我应该在哪里捕获该错误以显示验证消息而不是让页面崩溃到 500 错误?