Get all records with the same Field1 and different Field2 Django ORM
Good afternoon! I have a model of the following format
class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='orders')
address = models.CharField(max_length=255, null=True, blank=True)
....
I need to get all the records with the same address, but with different user.
Tell me, please, how can I fulfill this request?
A request in this format outputs an error
orders = Order.objects\
.filter(...)\
.distinct('address', 'user')\
.annotate(Count('address')\
.filter(address__count_gt=1)
NotImplementedError: annotate() + distinct(fields) is not implemented.
And if so, then count counts incorrectly and I lose data because of values (I need not to lose the order object)
orders = Order.objects\
.filter(...)\
.values('address', 'user')\
.distinct()\
.annotate(Count('address')\
.filter(address__count_gt=1)