How to handle the for loop in a django formset?
up vote
0
down vote
favorite
the problem with my formset is that it does not take into account the amount of the modified article in the for loop, and i would also like to know how can i get the total sales perform. thank you
views.py :
def post(self, request):
vente_formset = self.VenteFormSet(self.request.POST)
if vente_formset.is_valid():
for temp in vente_formset:
vente = temp.save()
article = vente.id_article
print('article de départ', article.quantite)
entre = article.quantite
entre -= vente.quantite_v
if entre >= 0:
article.quantite -= vente.quantite_v
article.save()
print('article final', article.quantite)
else:
vente.delete()
messages.warning(request, 'Stock insuffisant pour cette opération!')
else:
messages.warning(request, 'Formulaire invalide!')
return render(request, self.template_name, {'form': self.VenteFormSet()})
in terminal pycharm :
-->article debut 15
.article fin 10
-->article debut 15
.article fin 8
what I wish to have :
-->article debut 15
.article fin 10
-->article debut 10
.article fin 3
django
add a comment |
up vote
0
down vote
favorite
the problem with my formset is that it does not take into account the amount of the modified article in the for loop, and i would also like to know how can i get the total sales perform. thank you
views.py :
def post(self, request):
vente_formset = self.VenteFormSet(self.request.POST)
if vente_formset.is_valid():
for temp in vente_formset:
vente = temp.save()
article = vente.id_article
print('article de départ', article.quantite)
entre = article.quantite
entre -= vente.quantite_v
if entre >= 0:
article.quantite -= vente.quantite_v
article.save()
print('article final', article.quantite)
else:
vente.delete()
messages.warning(request, 'Stock insuffisant pour cette opération!')
else:
messages.warning(request, 'Formulaire invalide!')
return render(request, self.template_name, {'form': self.VenteFormSet()})
in terminal pycharm :
-->article debut 15
.article fin 10
-->article debut 15
.article fin 8
what I wish to have :
-->article debut 15
.article fin 10
-->article debut 10
.article fin 3
django
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
the problem with my formset is that it does not take into account the amount of the modified article in the for loop, and i would also like to know how can i get the total sales perform. thank you
views.py :
def post(self, request):
vente_formset = self.VenteFormSet(self.request.POST)
if vente_formset.is_valid():
for temp in vente_formset:
vente = temp.save()
article = vente.id_article
print('article de départ', article.quantite)
entre = article.quantite
entre -= vente.quantite_v
if entre >= 0:
article.quantite -= vente.quantite_v
article.save()
print('article final', article.quantite)
else:
vente.delete()
messages.warning(request, 'Stock insuffisant pour cette opération!')
else:
messages.warning(request, 'Formulaire invalide!')
return render(request, self.template_name, {'form': self.VenteFormSet()})
in terminal pycharm :
-->article debut 15
.article fin 10
-->article debut 15
.article fin 8
what I wish to have :
-->article debut 15
.article fin 10
-->article debut 10
.article fin 3
django
the problem with my formset is that it does not take into account the amount of the modified article in the for loop, and i would also like to know how can i get the total sales perform. thank you
views.py :
def post(self, request):
vente_formset = self.VenteFormSet(self.request.POST)
if vente_formset.is_valid():
for temp in vente_formset:
vente = temp.save()
article = vente.id_article
print('article de départ', article.quantite)
entre = article.quantite
entre -= vente.quantite_v
if entre >= 0:
article.quantite -= vente.quantite_v
article.save()
print('article final', article.quantite)
else:
vente.delete()
messages.warning(request, 'Stock insuffisant pour cette opération!')
else:
messages.warning(request, 'Formulaire invalide!')
return render(request, self.template_name, {'form': self.VenteFormSet()})
in terminal pycharm :
-->article debut 15
.article fin 10
-->article debut 15
.article fin 8
what I wish to have :
-->article debut 15
.article fin 10
-->article debut 10
.article fin 3
django
django
asked 22 hours ago
Sarindra Therese
32
32
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408103%2fhow-to-handle-the-for-loop-in-a-django-formset%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown