Customer.objects.filter(customer_id__in=contact_list_senders)
contact_list_senders是重複查詢集,涉及一些CUSTOMER_IDS:django的objects.filter(x__in = y),其中y是重複查詢集
{sender_id1,sender_id2,sender_id1,sender_id2,sender_id1}
當我試圖找到從contact_list_senders QuerySet的客戶對象與上面的代碼
實際輸出:
{customer1表,顧客2}
所需的輸出
{customer1表,顧客2,customer1表,顧客2,customer1表}
我瞭解實際輸出有道理的,因爲只有2個Customer對象與這些聯繫人匹配。你能幫我取得理想的結果嗎?
models.py:
class Customer(models.Model):
customer_id = models.CharField(max_length=244, blank=False, null=False)
first_name = models.CharField(max_length=244, blank=True, null=True)
last_name = models.CharField(max_length=244, blank=True, null=True)
email = models.CharField(max_length=244, blank=False, null=False)
enrollment_method = models.CharField(max_length=244, blank=True, null=False)
account_balance = models.DecimalField(default=0000.00, max_digits=6, decimal_places=2)
reserved_balance = models.DecimalField(default=0000.00, max_digits=6, decimal_places=2)
modified = models.DateTimeField(auto_now_add=True)
created = models.DateTimeField(auto_now_add=True)
看起來你必須用list_sender做一個循環,然後將結果合併成一個。 – viviwill