B
B
BotaniQ_Q2017-07-14 11:40:52
Django
BotaniQ_Q, 2017-07-14 11:40:52

Field for uploading pictures, videos and django documents?

I'm making a Django blog, now my models.py looks like this:

from django.db import models
from django.utils import timezone



class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=200)
    text = models.TextField()
    created_date = models.DateTimeField(
            default=timezone.now)
    published_date = models.DateTimeField(
            blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.title

I try to add this line
image = ImageField(upload_to='images/', null=True, blank=True)

however, django complains that it doesn't know what an ImageField is.
Ideally, I would like to make a field in the admin panel where I could upload several pictures, videos and attach some kind of document

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Innokentiev, 2017-07-14
@artinnok

image = models.ImageField(upload_to='images/', null=True, blank=True)

or for files:
There is no such functionality in the standard package, you will have to write a custom solution or look for a ready-made package.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question