Answer the question
In order to leave comments, you need to log in
Why is the image not saved?
Why is the image not saved?
I save through the model.
model
class Article(models.Model):
title = models.CharField(max_length=230, default='0')
url = models.SlugField(max_length=250, blank=True)
description = models.TextField(default='0')
edit = models.TextField(default='0')
show = models.BooleanField(default=False)
author = models.ForeignKey(User, models.SET_NULL, blank=True, null=True)
enc = models.ForeignKey(ListEnc, models.SET_NULL, blank=True, null=True)
updated = models.DateTimeField(auto_now=True)
create = models.DateTimeField(auto_now_add=True)
class ImageArticle(models.Model):
image = models.ImageField(upload_to=get_file_path, blank=False, default='')
article = models.ForeignKey(Article, on_delete=models.CASCADE)
create = models.DateTimeField(auto_now_add=True)
def Img(request, views):
if request.method == 'POST':
img = ImageArticle(article_id= 4)
img.image = request.FILES['0']
img.save()
def Img(request, views):
if request.method == 'POST':
img = ImageArticle()
img.image = request.FILES['0']
img.save()
Answer the question
In order to leave comments, you need to log in
Sometimes it seems to me that such questions are trolling!
img = ImageArticle()
img.article = Article.objects.get(pk=4)
img.image=request.FILES['0']
img.save()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question