I'm building a form that allows the user to add the different features of a product, and I also want it to be a dynamic form so the user can put whatever categories he want in it. Something like,
Form:
Name: shirt
Description: ...
Categorie1: Color: Red
Categorie2: Sleeve: short
Categorie3: ...
Add new categorie
Save
The problem is that I'm using CreateView for this page and don't know how to convert my form into a dynamic one. There's a way for doing this? or it's better to make it with a function view instead of CreateView?
Here's my code,
view:
class ProductCreateView(CreateView):
template_name = "product_create.html"
form_class = ProductModelForm
queryset = Product.objects.all()
def form_valid(self, form):
return super().form_valid(form)
model:
class Product(models.Model):
title = models.CharField(max_length = 120)
description = models.TextField()
image = models.FileField(upload_to="products/images/")
price = models.IntegerField()
active = models.BooleanField(default = True)
categorie = models.CharField(max_lenght = 50, default = '')
def get_absolute_url(self):
return reverse("products:product-detail", kwargs={"id": self.id})
def delete(self, *args, **kwargs):
self.image.delete()
super().delete(*args,**kwargs)
form:
class ProductModelForm(forms.ModelForm):
class Meta:
model = Product
fields = [
'title',
'description',
'image',
'price',
'active',
'categorie'
]
Thank you in advance!