Answer the question
In order to leave comments, you need to log in
How to properly redirect to a django admin form with a POST pass?
I have a page template item.html, in this template there is a form:
<!--shop/templates/shop/item.html-->
<form action="{% url 'admin:supplier_prodsupp_add' %}" method="post">
{% csrf_token %}
<input type="hidden" name="product" value="{{ item.id }}">
<input type="submit" class="btn btn-primary mb-3" value="Создать новую связку">
</form>
#supplier/models.py
class ProdSupp(models.Model):
product = models.ForeignKey('shop.Product', on_delete=models.CASCADE, verbose_name='Товар')
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE, verbose_name='Поставщик')
art = models.CharField('Артикул', max_length=15)
url_prod = models.URLField('Ссылка')
price = models.DecimalField('Цена', max_digits=9, decimal_places=2)
class Meta:
verbose_name = 'Связка товар поставщик'
verbose_name_plural = 'Связки товар поставщик'
unique_together = ('product', 'supplier')
def __str__(self):
return str(self.product)
{% url 'admin:supplier_prodsupp_add' %}
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