如何在django中按模型创建滑块?

时间:2021-07-14 18:04:34

In my Django project I have Slider model. Can someone help me create a slider by this model? I am a little bit confused and need some ideas. I would be grateful for any help.

在我的Django项目中,我有Slider模型。有人可以帮我创建这个模型的滑块吗?我有点困惑,需要一些想法。我将不胜感激任何帮助。

models.py:

class Slider(models.Model):
    head = models.CharField(
        max_length=250,
        help_text='Header',
        blank=False
    )

    body = models.TextField(
        help_text='Description',
        blank=False
    )

    idx = models.IntegerField(
        help_text='Field to sort',
        default=0,
        blank=True
    )

    class Meta:
        ordering = ['idx', 'pk']

1 个解决方案

#1


0  

Your model slider need a field for the image and a foreign key to a model Carousel that holds all the n images. So when you shows a Carousel you have n slider with its images and texts each one.

您的模型滑块需要一个图像字段和一个包含所有n个图像的模型Carousel的外键。因此,当您显示Carousel时,您有n个滑块及其图像和文本。

class Slider(models.Model):
   imagen=models.ImageField()
   carousel=models.ForeignKey(models.Carousel)
   head=...
   body=...

#1


0  

Your model slider need a field for the image and a foreign key to a model Carousel that holds all the n images. So when you shows a Carousel you have n slider with its images and texts each one.

您的模型滑块需要一个图像字段和一个包含所有n个图像的模型Carousel的外键。因此,当您显示Carousel时,您有n个滑块及其图像和文本。

class Slider(models.Model):
   imagen=models.ImageField()
   carousel=models.ForeignKey(models.Carousel)
   head=...
   body=...