我有一个M2M的关系,比客户可以从商店退订。你知道吗
以下是我的简化模型:
class Shop(models.Model):
# ...
unsubs = models.ManyToManyField(CliProfile, through='Unsubscriptions')
class CliProfile(models.Model):
# ... The M2M is not repeated here to respect DRY
class Unsubscriptions(models.Model):
shop = models.ForeignKey(Shop)
client = models.ForeignKey(CliProfile)
我想编写一个方法,它在参数中接受Cliprofile
对象的查询集,并返回只取消订阅的客户机。这是我所说的,但显然不起作用。你知道吗
class CliProfile(models.Model):
#...
@classmethod
def get_subscribed_clients(cls, shop, base_clients):
return base_clients.filter(shop_set__in=shop)
# This is exactly the opposite I want to do here !!
# I should filter when shop is in base_clients.shop_set.
Django的语法是什么?我怀疑这很容易,但即使阅读了医生,我仍然困惑于疑问。谢谢。你知道吗
在
QuerySet
上操作的方法的模式是使用模型管理器。你知道吗相关问题 更多 >
编程相关推荐