How do I prevent orders from being displayed repeatedly on the checkout screen when selecting multiple times
For my store, I basically have a quantity box with an add item option. When I select the quantity and click on the add item, the order gets added to my list of orders and it is displayed on checkout. However, Suppose I Select Order A for the first time and set quantity as 5. The second time, I selected Order A again and set quantity as 3, I want it to add to the previous order and display quantity as 8. However, in case of my code, it displays it as separate orders. How do I solve this issue?
views.py
def addItem(request):
selected_supply = Supply.objects.get(pk=request.POST['supplyID'])
qty = request.POST['qty']
try:
current_order = Order.objects.filter(owner=1).get(status="pre-place")
except Order.DoesNotExist:
current_order = Order.objects.create(owner=Manager.objects.get(pk=1), status="pre-place")
order_detail = OrderDetail.objects.create(orderID=current_order, supplyID=selected_supply, quantity=qty)
return HttpResponseRedirect(reverse('Store:browse'))
models.py
class OrderDetail(models.Model): #change to orderitem
orderID = models.ForeignKey(Order, on_delete=models.CASCADE)
supplyID = models.ForeignKey(Supply, on_delete=models.CASCADE)
quantity = models.IntegerField()
def __str__(self):
return f'{self.orderID.pk}: {self.supplyID.name} {self.quantity}'
class Order(models.Model):
owner = models.ForeignKey(ClinicManager, on_delete=models.CASCADE)
priority = models.CharField(max_length=200, blank=True)
weight = models.DecimalField(max_digits=4, decimal_places=2, default=0.00)
status = models.CharField(max_length=200)
placeTime = models.DateTimeField(default=datetime.now())
dispatchTime = models.DateTimeField(default=datetime.now())
deliveredTime = models.DateTimeField(default=datetime.now())
def __str__(self):
return f'{self.pk}'
def __lt__(self, other):
if (self.priority == other.priority):
return self.placeTime < other.placeTime
elif (self.priority == "High"):
return True
elif (other.priority == "Low"):
return True
else:
return False
django python-3.x
|
show 1 more comment
For my store, I basically have a quantity box with an add item option. When I select the quantity and click on the add item, the order gets added to my list of orders and it is displayed on checkout. However, Suppose I Select Order A for the first time and set quantity as 5. The second time, I selected Order A again and set quantity as 3, I want it to add to the previous order and display quantity as 8. However, in case of my code, it displays it as separate orders. How do I solve this issue?
views.py
def addItem(request):
selected_supply = Supply.objects.get(pk=request.POST['supplyID'])
qty = request.POST['qty']
try:
current_order = Order.objects.filter(owner=1).get(status="pre-place")
except Order.DoesNotExist:
current_order = Order.objects.create(owner=Manager.objects.get(pk=1), status="pre-place")
order_detail = OrderDetail.objects.create(orderID=current_order, supplyID=selected_supply, quantity=qty)
return HttpResponseRedirect(reverse('Store:browse'))
models.py
class OrderDetail(models.Model): #change to orderitem
orderID = models.ForeignKey(Order, on_delete=models.CASCADE)
supplyID = models.ForeignKey(Supply, on_delete=models.CASCADE)
quantity = models.IntegerField()
def __str__(self):
return f'{self.orderID.pk}: {self.supplyID.name} {self.quantity}'
class Order(models.Model):
owner = models.ForeignKey(ClinicManager, on_delete=models.CASCADE)
priority = models.CharField(max_length=200, blank=True)
weight = models.DecimalField(max_digits=4, decimal_places=2, default=0.00)
status = models.CharField(max_length=200)
placeTime = models.DateTimeField(default=datetime.now())
dispatchTime = models.DateTimeField(default=datetime.now())
deliveredTime = models.DateTimeField(default=datetime.now())
def __str__(self):
return f'{self.pk}'
def __lt__(self, other):
if (self.priority == other.priority):
return self.placeTime < other.placeTime
elif (self.priority == "High"):
return True
elif (other.priority == "Low"):
return True
else:
return False
django python-3.x
What'sOrderDetail
andSupply
in this? You only talk aboutOrder
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.
– dirkgroten
Nov 20 '18 at 9:53
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
"I select Order A" doesn't make sense looking at your view, since theOrder
object isn't determined by any selection (you don't userequest.POST
parameter to select anOrder
).
– dirkgroten
Nov 20 '18 at 9:57
updated with models
– Nayo xx
Nov 20 '18 at 9:58
2
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04
|
show 1 more comment
For my store, I basically have a quantity box with an add item option. When I select the quantity and click on the add item, the order gets added to my list of orders and it is displayed on checkout. However, Suppose I Select Order A for the first time and set quantity as 5. The second time, I selected Order A again and set quantity as 3, I want it to add to the previous order and display quantity as 8. However, in case of my code, it displays it as separate orders. How do I solve this issue?
views.py
def addItem(request):
selected_supply = Supply.objects.get(pk=request.POST['supplyID'])
qty = request.POST['qty']
try:
current_order = Order.objects.filter(owner=1).get(status="pre-place")
except Order.DoesNotExist:
current_order = Order.objects.create(owner=Manager.objects.get(pk=1), status="pre-place")
order_detail = OrderDetail.objects.create(orderID=current_order, supplyID=selected_supply, quantity=qty)
return HttpResponseRedirect(reverse('Store:browse'))
models.py
class OrderDetail(models.Model): #change to orderitem
orderID = models.ForeignKey(Order, on_delete=models.CASCADE)
supplyID = models.ForeignKey(Supply, on_delete=models.CASCADE)
quantity = models.IntegerField()
def __str__(self):
return f'{self.orderID.pk}: {self.supplyID.name} {self.quantity}'
class Order(models.Model):
owner = models.ForeignKey(ClinicManager, on_delete=models.CASCADE)
priority = models.CharField(max_length=200, blank=True)
weight = models.DecimalField(max_digits=4, decimal_places=2, default=0.00)
status = models.CharField(max_length=200)
placeTime = models.DateTimeField(default=datetime.now())
dispatchTime = models.DateTimeField(default=datetime.now())
deliveredTime = models.DateTimeField(default=datetime.now())
def __str__(self):
return f'{self.pk}'
def __lt__(self, other):
if (self.priority == other.priority):
return self.placeTime < other.placeTime
elif (self.priority == "High"):
return True
elif (other.priority == "Low"):
return True
else:
return False
django python-3.x
For my store, I basically have a quantity box with an add item option. When I select the quantity and click on the add item, the order gets added to my list of orders and it is displayed on checkout. However, Suppose I Select Order A for the first time and set quantity as 5. The second time, I selected Order A again and set quantity as 3, I want it to add to the previous order and display quantity as 8. However, in case of my code, it displays it as separate orders. How do I solve this issue?
views.py
def addItem(request):
selected_supply = Supply.objects.get(pk=request.POST['supplyID'])
qty = request.POST['qty']
try:
current_order = Order.objects.filter(owner=1).get(status="pre-place")
except Order.DoesNotExist:
current_order = Order.objects.create(owner=Manager.objects.get(pk=1), status="pre-place")
order_detail = OrderDetail.objects.create(orderID=current_order, supplyID=selected_supply, quantity=qty)
return HttpResponseRedirect(reverse('Store:browse'))
models.py
class OrderDetail(models.Model): #change to orderitem
orderID = models.ForeignKey(Order, on_delete=models.CASCADE)
supplyID = models.ForeignKey(Supply, on_delete=models.CASCADE)
quantity = models.IntegerField()
def __str__(self):
return f'{self.orderID.pk}: {self.supplyID.name} {self.quantity}'
class Order(models.Model):
owner = models.ForeignKey(ClinicManager, on_delete=models.CASCADE)
priority = models.CharField(max_length=200, blank=True)
weight = models.DecimalField(max_digits=4, decimal_places=2, default=0.00)
status = models.CharField(max_length=200)
placeTime = models.DateTimeField(default=datetime.now())
dispatchTime = models.DateTimeField(default=datetime.now())
deliveredTime = models.DateTimeField(default=datetime.now())
def __str__(self):
return f'{self.pk}'
def __lt__(self, other):
if (self.priority == other.priority):
return self.placeTime < other.placeTime
elif (self.priority == "High"):
return True
elif (other.priority == "Low"):
return True
else:
return False
django python-3.x
django python-3.x
edited Nov 20 '18 at 10:00
Daniel Roseman
446k41577634
446k41577634
asked Nov 20 '18 at 9:45


Nayo xxNayo xx
62
62
What'sOrderDetail
andSupply
in this? You only talk aboutOrder
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.
– dirkgroten
Nov 20 '18 at 9:53
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
"I select Order A" doesn't make sense looking at your view, since theOrder
object isn't determined by any selection (you don't userequest.POST
parameter to select anOrder
).
– dirkgroten
Nov 20 '18 at 9:57
updated with models
– Nayo xx
Nov 20 '18 at 9:58
2
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04
|
show 1 more comment
What'sOrderDetail
andSupply
in this? You only talk aboutOrder
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.
– dirkgroten
Nov 20 '18 at 9:53
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
"I select Order A" doesn't make sense looking at your view, since theOrder
object isn't determined by any selection (you don't userequest.POST
parameter to select anOrder
).
– dirkgroten
Nov 20 '18 at 9:57
updated with models
– Nayo xx
Nov 20 '18 at 9:58
2
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04
What's
OrderDetail
and Supply
in this? You only talk about Order
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.– dirkgroten
Nov 20 '18 at 9:53
What's
OrderDetail
and Supply
in this? You only talk about Order
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.– dirkgroten
Nov 20 '18 at 9:53
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
"I select Order A" doesn't make sense looking at your view, since the
Order
object isn't determined by any selection (you don't use request.POST
parameter to select an Order
).– dirkgroten
Nov 20 '18 at 9:57
"I select Order A" doesn't make sense looking at your view, since the
Order
object isn't determined by any selection (you don't use request.POST
parameter to select an Order
).– dirkgroten
Nov 20 '18 at 9:57
updated with models
– Nayo xx
Nov 20 '18 at 9:58
updated with models
– Nayo xx
Nov 20 '18 at 9:58
2
2
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53390189%2fhow-do-i-prevent-orders-from-being-displayed-repeatedly-on-the-checkout-screen-w%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53390189%2fhow-do-i-prevent-orders-from-being-displayed-repeatedly-on-the-checkout-screen-w%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
What's
OrderDetail
andSupply
in this? You only talk aboutOrder
in your description. Please be more specific about what's happening, and what result you're expecting in terms of the objects you use in your view. Rephrase your own question rather than adding details in the comments.– dirkgroten
Nov 20 '18 at 9:53
Sorry. I forgot to add the models/ Order detail contains the order ID supply ID and quantity. My order consists of the owner, weight, status, priority, dispatch time etc
– Nayo xx
Nov 20 '18 at 9:55
"I select Order A" doesn't make sense looking at your view, since the
Order
object isn't determined by any selection (you don't userequest.POST
parameter to select anOrder
).– dirkgroten
Nov 20 '18 at 9:57
updated with models
– Nayo xx
Nov 20 '18 at 9:58
2
I'm not sure what you are finding hard here. You already know how to get an existing item and update it, as you do it with Order. Why can't you do the same thing with OrderDetail: find any existing OrderDetail for that order with that supplyId and update its quantity, or if it doesn't exist create a new one.
– Daniel Roseman
Nov 20 '18 at 10:04