Last modified: Jan 10, 2023 By Alexander Williams

Django models.FileField [Examples]

Example 1


class Hokkaido(models.Model):
    city_name = models.CharField(max_length=55)
    city_name_ja = models.CharField(max_length=55)
    post_date = models.DateTimeField(auto_now=True)
    predicted_data = models.FileField(upload_to='data/')
    wind_data = models.FileField(upload_to='data/', null=True)
    wind_tendency = models.FileField(upload_to='data/', null=True)

Example 2


class Miyagi(models.Model):
    city_name = models.CharField(max_length=55)
    city_name_ja = models.CharField(max_length=55)
    post_date = models.DateTimeField(auto_now=True)
    predicted_data = models.FileField(upload_to='data/')
    wind_data = models.FileField(upload_to='data/', null=True)
    wind_tendency = models.FileField(upload_to='data/', null=True)

Example 3


class StaticFile(models.Model):
    CHOICES = (
        ('JS', 'JS'),
        ('CSS', 'CSS'),
    )
    name = models.CharField(max_length=300, unique=True)
    file_type = models.CharField(max_length=300, choices=CHOICES)
    file = models.FileField(upload_to="static")

    def __str__(self):
        return self.name

Example 4


class today_stories(models.Model):
    image = models.ImageField(upload_to='pics')
    pdf = models.FileField(upload_to='pdf')
    Description = models.TextField('Description')

Example 5


class Input_audios(models.Model):
    keyword = models.TextField(max_length=20)
    audio_1 = models.FileField(upload_to='media')
    audio_2 = models.FileField(upload_to='media')
    audio_3 = models.FileField(upload_to='media')
    audio_analyse = models.FileField(upload_to='media')

Example 6


class Fantasia(models.Model):

    STATUS_CHOICES = (
            ('draft', 'Draft'),
            ('published', 'Published'),
            )

    title = models.CharField(max_length=250,null=True, blank=True)
    slug = models.SlugField(max_length=250, unique_for_date="publish")
    image = models.FileField(null=True, blank=True)
    image2 = models.FileField(null=True, blank=True)
    image3 = models.FileField(null=True, blank=True)
    video = models.FileField(null=True, blank=True)
    link = models.URLField(blank=True, null=True)
    body = models.TextField(blank=True)
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="draft")
    published = PublishedManager()
    tags = TaggableManager()
    objects = models.Manager()