Почему не сохраняется картинка?
Сохраняю через модель.
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()
Выводит:
TypeError: __init__() got an unexpected keyword argument 'article_id'
А если так попытаюсь сохранить, то
def Img(request, views):
if request.method == 'POST':
img = ImageArticle()
img.image = request.FILES['0']
img.save()
Выводит:
django.db.utils.IntegrityError: (1048, "Column 'article_id' cannot be null")