how can I return a looped values in a method that no using array, for now i am using an array.
here is my code :
def get_ticket_sum_quantity(self, product_id, date_select):
prod = Product.objects.get(id=product_id)
sumOfQuantity = Ticket.objects.filter(date_select=date_select, product=prod).aggregate(Sum('quantity'))['quantity__sum']
if sumOfQuantity == None:
sumOfQuantity = 0
prodAvailable = prod.quantity - sumOfQuantity
return prodAvailable
def get_ticket_available_product(self, date_select, client_id, quantity):
client = Client.objects.get(id=client_id)
prodCount = Product.objects.filter(client=client_id,status='Active').values_list('id', flat=True)
array = []
for id in prodCount:
prodAvailable = Ticket.objects.get_ticket_sum_quantity(id, date_select)
prodAvailable = prodAvailable - quantity
if prodAvailable < 0:
data = {'id':id}
else :
data = {'id':id}
data = data['id']
array.append(data)
return array
and when i used it and the out-put is...
Ticket.objects.get_ticket_available_product('2011-12-29', 5, 1)
[3, 2, 6, 1]
my question is, is there any other options that I will be not using an array so that it will return like this?
3
2
6
1