I have a list and I want to find whether any items in this list are not in the database.
Using the object.exclude()
Django function I only find which elements are in my database that are not in my list:
Gene.objects.exclude(gene_name__in=self.gene_list)
I am currently getting the items I have in my list that aren't in the database using this code:
obj = Gene.objects.filter(gene_name__in=self.gene_list)
database_genes = [o.gene_name for o in obj]
genes_not_in_db = [g for g in self.gene_list if g not in database_genes]
This is however rather messy - is there a better way / inbuilt Django function to do this? Thanks