[英]need id's of objects from Django query where customer id's are distinct - DB mysql
楷模 -
class CfgXmppSessions(models.Model):
objid = models.AutoField(primary_key=True)
customer_objid = models.ForeignKey('CstContact', blank=True, null=True, on_delete=models.DO_NOTHING,db_constraint=False, db_column='customer_objid', db_index=False)
character_name = models.CharField(max_length=45)
character_channel_type = models.CharField(max_length=45, blank=True, null=True)
character_objid = models.ForeignKey('PerfCharacter', blank=True, null=True, on_delete=models.DO_NOTHING,db_constraint=False, db_column='character_objid', db_index=False)
我想要所有客戶都是獨一無二的 objid
嘗試類似:
def GetObjectID():
customerIDs = list(CfgXmppSessions.objects.values('customer_objid').distinct())
objectIDs = []
for id in customerIDs:
objectIDs.append(CfgXmppSessions.objects.filter(customer_objid = f"{id}").values("customer_objid"))
return objectIds
objids = [session.get('max_objid') for session in list(CfgXmppSessions
.objects.filter(character_objid=9100)
.values('customer_objid')
.annotate(max_objid=Max('objid')))]
這對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.