如何使用Python Django模型在PostgreSQL中获得数组字段的长度
这是我的django模型:
class UserVpaUpiId(models.Model):
user_id = models.IntegerField(db_index=True, unique=True)
vpa_upi_id = models.TextField(null=False, blank=True)
created_on = models.DateTimeField(auto_now_add=True, null=False)
updated_on = models.DateTimeField(auto_now=True, null=False)
我想用特定的user_id删除一个条目,我可以成功地使用它:
UserVpaUpiId.objects.filter(user_id=user_id).delete()
想显示upis的数量,upis的数量存储在vpa_upi_id中:
["acbd.pq@icici", "9987654431@apl", "9876543210@apl"]
但是,在此之前,我 我可以实现吗?
This is my Django model:
class UserVpaUpiId(models.Model):
user_id = models.IntegerField(db_index=True, unique=True)
vpa_upi_id = models.TextField(null=False, blank=True)
created_on = models.DateTimeField(auto_now_add=True, null=False)
updated_on = models.DateTimeField(auto_now=True, null=False)
I want to delete an entry with a particular user_id, which I am able to do successfully using:
UserVpaUpiId.objects.filter(user_id=user_id).delete()
But, before that, I want to display the number of UPIs, which are stored in vpa_upi_id in the format:
["acbd.pq@icici", "9987654431@apl", "9876543210@apl"]
How can I achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您已经必须使用User_id才能删除记录,因此您可以获取匹配记录,将结果转换为字符串并执行一些字符串操作以将其转换为阵列,然后您可以抓住长度。
Since you already have to user_id to delete the record you can grab the matching record(s), convert the result into a string and perform some string manipulations to turn it into an array where you can then grab the length.