我正在尝试在两个用户之间进行转换。
models.py
class Trasaction(models.Model):
sender = models.ForeignKey(
Account, on_delete=models.PROTECT
)
receiver = models.ForeignKey(
Account, on_delete=models.PROTECT
)
amount = models.IntegerField()
purpose = models.CharField(max_length=100, null=True, blank=True)
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"{self.sender.username}"
我想查询用户是发送者或接收者的所有事务。
views.py
def transactions_log(request):
user = request.user
transactions = Transactions.objects.filter #am stuck
return render(request, "trasaction.html")
1条答案
按热度按时间njthzxwz1#
尝试使用
Q
对象,如下所示: