I am using class based views for a form but image is not uploading in db, not showing any errors. here is my models.py
class ProductCreateModel(models.Model):
user = models.ForeignKey('accounts.SellerProfileModel',
related_name='product_seller',
on_delete=models.CASCADE,editable=False)
title = models.CharField(max_length=120)
slug = models/.SlugField(max_length=255,unique=True,blank=True)
description = models.TextField(max_length=250)
orignal_price = models.DecimalField(decimal_places=2, max_digits=8)
discount = models.DecimalField(decimal_places=2,max_digits=4)
discount_price = models.DecimalField(decimal_places=2,max_digits=8)
image1 = models.ImageField(upload_to=upload_image_path,blank=True,null=True)
here is my forms.py
from django import forms
from .models import ProductCreateModel
class ProductCreateForm(forms.ModelForm):
class Meta:
model = ProductCreateModel
fields = '__all__'
here is my views.py
class ProductCreateView(views.LoginRequiredMixin,ActiveSellerOnlyMixin,generic.CreateView,):
template_name = 'products/create_new_product.html'
model = ProductCreateModel
form_class = ProductCreateForm
success_url = reverse_lazy('home')
def form_valid(self, form):
product = form.save(commit=False)
user = get_current_user(self.request)
image1 = form.cleaned_data['image1']
form.instance.user = request.user
return super(ProductCreateView, self).form_valid(form)
# product.save()
Now the form is submitted successfully but image is empty.
Submit Form