Данные формы модели Django не сохраняются в базе данных
Я новичок в программировании и django. Данные формы модели не сохраняются в базе данных, я не могу понять почему. Я пробовал разные способы проверки формы, но это просто не работает.
Вот мой views.py:
@login_required(login_url ='/seller/login')
@seller()
def addProductsView(request):
pform = ProductForm(request.POST or None, request.FILES or None)
if pform.is_valid():
pform.save()
else:
messages.warning(request, 'Oops! Something went wrong')
return render(request, 'Shop/product-form.html', {'pform':pform})
А это мой models.py:
class Products(models.Model):
seller = models.ForeignKey(SellerProfile, on_delete = models.CASCADE)
title = models.CharField(max_length = 255)
product_category = models.CharField(choices = CATEGORY_CHOICES, max_length = 100, default = 'eBooks')
description = models.TextField()
price = models.FloatField(max_length= 5)
discounted_price = models.FloatField(max_length= 5, default = 0.00)
thumbnail = models.ImageField(upload_to = 'media/thumbnail/',null=True)
files = models.FileField(upload_to = 'media/product_files/', null = True)
slug = models.SlugField(max_length = 255, unique = True, null = True, blank = True)
is_featured = models.BooleanField(default = False)
is_published = models.BooleanField(default = True)
А это forms.py:
class ProductForm(ModelForm):
class Meta:
model = Products
fields = ['title', 'product_category', 'description', 'price', 'discounted_price', 'thumbnail', 'files']
Любая помощь будет очень полезна. Спасибо