I have two models:
class A(models.Model):
field1 = models.CharField(max_length=100)
field2 = models.CharField(max_length=100)
class B(models.Model):
a_field = models.ForeignKey(null=True,blank=True,related_name='a',on_delete=models.SET_NULL)
field2 = models.CharField(max_length=100)
I want to get all of elements of model A which are not related to B.
Here is the query I wrote but it doesn't work:
B.objects.select_related("a_field").filter(a_field__isnull=True)
How can I solve this problem?