Доброго времени суток.
Или я совсем глупый или я уже не знаю.
Второй день мучаюсь, не могу осуществить удаление из modelformset кнопкой на сайте.
Собственно сам кусок шаблона{{ formset.management_form }}
{% for form in formset %}
{{ form.id }}
{{ form.DELETE }}
<tr class="edt {% if forloop.first %} shadow {% endif %}"
{% if forloop.counter|divisibleby:"2" %}style="background-color: white"
{% else %} style="background-color: #F2F2F2"
{% endif %}>
<td> {{ form.title }} </td>
<td>{{ form.priceMazut }} </td>
<td>{{ form.priceSPBT }} </td>
<td>{{ form.priceDTl }} </td>
<td>{{ form.priceDTm }} </td>
<td>{{ form.priceDTz }} </td>
<td class="last"></td>
</tr>
{% endfor %}
вот viewdef manage_articles(request):
if not request.user.is_staff:
return redirect('/')
ArticleFormSet = modelformset_factory(Article, fields=('title', 'priceMazut', 'priceSPBT',
'priceDTl', 'priceDTm', 'priceDTz'))
if request.method == 'POST':
formset = ArticleFormSet(request.POST, request.FILES)
if formset.is_valid():
formset.save()
return redirect('/?$')
else:
formset = ArticleFormSet()
return render(request, "table/manage_articles.html", {"formset": formset})
forms.pyclass ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ('title', 'priceMazut', 'priceSPBT', 'priceDTl', 'priceDTm', 'priceDTz')
ArticleFormSet = modelformset_factory(Article, form=ArticleForm, can_delete=True)
formset = ArticleFormSet()
class ArticleFormSet(BaseModelFormSet):
def clean(self):
super(ArticleFormSet, self).clean()
for form in self.forms:
title = form.cleaned_data['title'].upper()
form.cleaned_data['title'] = title
form.instance.title = title
priceMazut = form.cleaned_data['priceMazut'].upper()
form.cleaned_data['priceMazut'] = priceMazut
form.instance.priceMazut = priceMazut
priceSPBT = form.cleaned_data['priceSPBT'].upper()
form.cleaned_data['priceSPBT'] = priceSPBT
form.instance.priceSPBT = priceSPBT
priceDTl = form.cleaned_data['priceDTl'].upper()
form.cleaned_data['priceDTl'] = priceDTl
form.instance.priceDTl = priceDTl
priceDTm = form.cleaned_data['priceDTm'].upper()
form.cleaned_data['priceDTm'] = priceDTm
form.instance.priceDTm = priceDTm
priceDTz = form.cleaned_data['priceDTz'].upper()
form.cleaned_data['priceDTz'] = priceDTz
form.instance.priceDTz = priceDTz
Удалил все свои тщетные попытки прописать удаление, голова кипит
Перечитывал документацию несколько раз
Видимо все таки совсем глупый