正确使用重复属性?

发布于 2024-12-29 09:41:23 字数 309 浏览 3 评论 0原文

我需要允许许多商品的订单/购买,例如

class Purchase(db.Model):
  '''a completed transaction'''
  item = db.ReferenceProperty(Item, repeated=True))

重复的关键字是否合法并以正确的方式使用?我还有哪些其他选择?我应该用重复的字符串属性来代替吗?

item_ids = model.StringProperty(repeated=True) 或重复的 KeyProperties? 谢谢

I need orders / purchases that allow many items for instance something like

class Purchase(db.Model):
  '''a completed transaction'''
  item = db.ReferenceProperty(Item, repeated=True))

Is the repeated keyword legal and used in the correct manner here? What are my other options? Should I do it with a repeated stringproperty instead?

item_ids = model.StringProperty(repeated=True)
or with repeated KeyProperties?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蘑菇王子 2025-01-05 09:41:23

有一个 ListProperty

class Purchase(db.Model):
    items = db.ListProperty(db.Key)

它的使用方式与 python 类似列表:

p = Purchase()
p.items = [item1.key(), item2.key(), item3.key()]

但在查询中它看起来像一个单值字段。 ListProperty 的每个值都单独索引。

下面的查询将返回包含 item1 的所有购买:

Purchase.all().filter('items =', item1.key())

下面的查询将返回包含 item1item2 的所有购买:

Purchase.all().wilter('items IN', [item1.key(), item2.key()])

如果您需要要对多个 ListProperty 建立索引,请不要忘记熟悉 爆炸索引

There is a ListProperty:

class Purchase(db.Model):
    items = db.ListProperty(db.Key)

It is used like a python list:

p = Purchase()
p.items = [item1.key(), item2.key(), item3.key()]

In queries however it looks like a single-valued field. Every value of ListProperty is indexed separately.

Query below will return all purchases which contain the item1:

Purchase.all().filter('items =', item1.key())

Query below will return all purchases which contain either item1 or item2:

Purchase.all().wilter('items IN', [item1.key(), item2.key()])

If you will ever need to index more than one ListProperty don't forget to familiarize your self with exploding-indexes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文