[英]need id's of objects from Django query where customer id's are distinct - DB mysql
Models -楷模 -
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)
I want all objid where customers are unique我想要所有客户都是独一无二的 objid
try something like:尝试类似:
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')))]
This works for me.这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.