[Django]-Django: Find an item in a list that is not in Database

3👍

Your way of dealing with is just what needs to be done but rather than using expensive array you should use sets/dict

genes = Gene.objects.filter(gene_name__in=self.gene_list).values('gene_name')
genes_set = set(gene.gene_name for gene in genes)
not_in_db = set(gene_list) - genes_set

Leave a comment