多个查询集
如何将 querySet 接口用于两个或更多模型?
例如:
assortments = get_list_or_404(Assortment, [some_list]) #this is content_types of each models
category = [ assortment.type.model_class() for assortment in assortments ]
all_goods = map(lambda cl: cl.objects.filter(has_shop=True, **kwargs).distinct(), category)
all_goods = reduce(lambda l,l1: l.extend(l1) or l, all_goods, [])
但现在我不能使用查询集方法,例如 order_by
我还能如何获取不同模型的对象列表?
How I can use querySet interface for two and more models?
for example:
assortments = get_list_or_404(Assortment, [some_list]) #this is content_types of each models
category = [ assortment.type.model_class() for assortment in assortments ]
all_goods = map(lambda cl: cl.objects.filter(has_shop=True, **kwargs).distinct(), category)
all_goods = reduce(lambda l,l1: l.extend(l1) or l, all_goods, [])
but now i cant use querysets methods, like order_by, for example
how else can i get list of objects from different models?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。查询集是单个模型类型实例的有序集合。不存在多个模型的查询集之类的东西。
You can't. A queryset is an ordered collection of instances of a single model type. There's no such thing as a queryset of multiple models.