繁体   English   中英

需要来自 Django 查询的对象 ID,其中客户 ID 是不同的 - DB mysql

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM