I have a model in my database called Item. This is the model
class Item(models.Model):
item_title = models.CharField("Item title: ", max_length=50)
item_description = models.CharField("Item description: ", max_length=200)
starting_price = models.FloatField( default = 0)
picture = models.ImageField(upload_to = 'gallery')
finishTime = models.DateTimeField("Finish time: ")
ownerID = models.ForeignKey(User, on_delete = models.CASCADE)
higestBid = models.FloatField()
highestBidderID = models.IntegerField(blank=True, default=-1)
active = models.BooleanField(default = True)
I want to create a function in views.py , which will check the 'active' field of each item in the database. How can I do that? I have tried to do this:
items = list(Item.object.values())
for i in range(items):
print(item[i].active)
However it does not work. Any help is appreciated
values()?Why would you calllist? Why would you userange? Why are you using an index? Why not justfor item in Item.objects.all(): print(item.active)?