我有我的意見@required_login
裝飾,但我需要我的ListView
只顯示與當前登錄的用戶相關的對象。Django過濾列表查看用戶
我想:
class NdaList(ListView):
form_class = NonDisclosureForm
template_name = 'nda/nda_list.html'
def get_queryset(self):
return NonDisclosure.objects.filter(user=self.request.user)
,但它給了我一個Cannot query "charles": Must be "Profile" instance.
我的模型:
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name="profile", verbose_name="user")
...
class NonDisclosure(Timestamp):
user = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name="nda", verbose_name="user")
...
我試圖盡我所能,但我仍然有限的Django的知識,我沒有想法。感謝您的時間。
發表您的settings.py文件 –