0
我有3個表格,TextObj,User,SecurityCheck。第三個表具有一個引用TextObj的外鍵屬性(textobj),並且存在從SecurityCheck到User的多對多字段(sharedWith)。django模型複雜查詢
class SecurityCheck(models.Model):
textobj=models.ForeignKey(TextObj)
owner=models.CharField(max_length=255)
sharedWith=models.ManyToManyField(User)
def __init__(self,owner,filename,requestingUsername):
self.owner=owner
self.textobj=TextObj.filter(filename=filename)
self.sharedWith.add(User.objects.filter(username=requestingUsername))
,我需要做哪些獲取具有在sharedWith領域特定用戶和特定的文件名(這是TextObj的屬性)
'TextObj.objects.filter(securitycheck__sharedWith =用戶,文件名...)' –
的反向查詢的外鍵允許嗎? –
是的,我已經添加了答案 –