OrderBy是一个ReferenceProperty中的一个属性

编程入门 行业动态 更新时间:2024-10-15 22:27:17
本文介绍了OrderBy是一个ReferenceProperty中的一个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道如何通过ReferenceProperty的属性对GqlQuery进行排序。

I don't know how to make a GqlQuery that order by a property of the ReferenceProperty.

在这种情况下,我想得到所有的座位,但是顺序通过房间的号码

In this case, I want to get all the Seat but order by the id of the Room

GqlQuery引用不允许加入,所以在这种情况下如何处理?

The GqlQuery reference does not allow a join, so how do you approach in this case?

class Room(db.Model): id = db.IntegerProperty() dimension = db.StringProperty(multiline=True)

一个房间有很多座位,每个都有一个id

a room has many seats, each with an id

class Seat(db.Model): id = db.IntegerProperty() roomId = db.ReferenceProperty(Room) seats_query = GqlQuery("SELECT * FROM Seat ") seats = seats_query.fetch(1000)

Alex是正确的,所以我决定不要触摸GqlQuery,而是尝试使用Django模板,我已经找到了解决方案来排序Seat by Room'id而无需添加新的字段在座位课。

Alex is right on his point, so I decided not to touch GqlQuery, and tried to play with Django template instead, I have found the solution to sort Seat by Room'id without having to add new field in Seat class.

如果有兴趣,我将代码放在这里;))Cheers;))

I put the code here if anyone has interests ;)) Cheers ;))

{% regroup seats|dictsort:"roomId.id" by roomId.id as room_list %} <ul> {% for room in room_list %} <li>Room: {{room.grouper}} <ul> {% for item in room.list %} <li>Seat no: {{item.id}} </li> {% endfor %} </ul> </li> {% endfor %} </ul>

推荐答案

一般来说,解决非关系数据库缺乏的JOIN功能,你反规范化;具体来说,您冗余地将数据放在多个位置,因此可以在您的查询中有效访问这些数据(这样做会使您的存储更新变得更麻烦,但是非关系数据库通常大量倾斜读取

In general, to work around non-relational DBs lack of JOIN functionality, you denormalize; specifically, you redundantly put data pieces in more than one place, so they can be effectively accessed in your queries (this does make it more cumbersome to update your store, but then, non-relational DBs in general are heavily slanted to read-mostly applications).

在这种情况下,您添加到 Seat 具有房间ID的属性 - 因为您有特别称为 roomId (而不是说, room )参考到座位的房间,我想你会把这个非规范化的位作为 roomIdId 。

In this case, you add to Seat a property with the room's id -- since you have peculiarly called roomId (rather than, say, room) the reference to the seat's room, I guess you'd have this denormalized bit as roomIdId.

更多推荐

OrderBy是一个ReferenceProperty中的一个属性

本文发布于:2023-06-08 21:33:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是一个   属性   OrderBy   ReferenceProperty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!