我有以下django模型:
class Video(models.Model):
# ... snip ...
# Entities detected using face tracking
faces = models.ManyToManyField(Entity, related_name="facevids", blank=True)
# Entities detected using speaker diarisation
speakers = models.ManyToManyField(Entity, related_name="speakervids", blank=True)
# Entities detected by extracting names from metadata and ocr
names = models.ManyToManyField(Entity, related_name="namevids", blank=True)
# Entities detected using logo detection
logos = models.ManyToManyField(Entity, related_name="logovids", blank=True)
class Entity(models.Model):
entity_id = models.CharField(primary_key = True, max_length = 100)
我想将自定义管理器添加到Entity
,以便我可以使用与allvids
或facevids
相同的方式访问speakervids
ManyToMany自定义字段。
到目前为止,我已经研究了如何访问和联合使用类似
的查询集@property
def allvids(self):
return (self.facevids.get_query_set() | self.speakervids.get_query_set() |
self.namevids.get_query_set() | self.logovids.get_query_set()).distinct()
但是这会返回一个queryset对象而不是Manager,这意味着allvids
的访问权限与facevids
,speakervids
等不一样。我更喜欢结束用户无需了解实施和访问allvids
与其他Manager字段完全相同。