[Answered ]-Django: why does my custom filter not find an existing item in the array?

1👍

Your reserved_places is a list of strings, not a list of integers, and 0 is not equal to '0'.

You should convert these to ints, so:

reserved_places = []
invoices = Invoice.objects.filter(event=selected_event)
for invoice in invoices:
    reserved_places += map(int, invoice.invoice_details.split(','))

But using a string with a (comma separated) list of integers might not be the best way to store reserved places in the first place (no pun intended): it makes it hard to query the database to look for example to an invoice where a certain item is selected, and also makes it a bit "incovenient" to query with Invoices to find the reserved seats.

Leave a comment