+
+
+class Carousel(models.Model):
+ slug = models.SlugField(_('slug'), unique=True)
+
+ class Meta:
+ ordering = ('slug',)
+ verbose_name = _('carousel')
+ verbose_name_plural = _('carousels')
+
+ def __str__(self):
+ return self.slug
+
+class CarouselItem(models.Model):
+ order = models.PositiveSmallIntegerField(_('order'), unique=True)
+ carousel = models.ForeignKey(Carousel, models.CASCADE, verbose_name=_('carousel'))
+ banner = models.ForeignKey(Cite, models.CASCADE, null=True, blank=True, verbose_name=_('banner'))
+ banner_group = models.ForeignKey(BannerGroup, models.CASCADE, null=True, blank=True, verbose_name=_('banner group'))
+
+ class Meta:
+ ordering = ('order',)
+ unique_together = [('carousel', 'order')]
+ verbose_name = _('carousel item')
+ verbose_name_plural = _('carousel items')
+
+ def __str__(self):
+ return str(self.banner or self.banner_group)
+
+ def clean(self):
+ if not self.banner and not self.banner_group:
+ raise ValidationError(_('Either banner or banner group is required.'))
+ elif self.banner and self.banner_group:
+ raise ValidationError(_('Either banner or banner group is required.'))