Answer the question
In order to leave comments, you need to log in
How to put a model in a form in Django?
It is necessary that the user can fill out the form on the site, and not in the admin panel.
There is this model:
class Product(models.Model):
title = models.CharField(max_length = 130)
slug = models.SlugField()
description = models.TextField()
image = models.ImageField()
prise = models.DecimalField(max_digits = 7, decimal_places=0)
available = models.BooleanField(default=True)
def __str__(self):
return self.title
def create_product(request):
form = ProductForm(request.POST)
if form.is_valid():
company = form.save()
return redirect(company)
else:
return render(request, 'product_form.html', {'form': form})
<form method="POST" action="/" > {% csrf_token %}
{{ form }}
<input type="submit" value="Добавить" >
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question