我有三个表 User、Users_clients 和 Credits。我想列出当前用户的客户表及其详细信息和信用。如果信用表中列出了任何客户,则信用应返回 0,否则应返回信用值。
我的model.py是
class User_clients(models.Model):
user = models.ForeignKey(User, related_name='myuser')
client = models.ForeignKey(User, related_name='myclient')
class Credits(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
credit = models.IntegerField(null=True, default=0)
我的views.py是
def clients(request):
try:
data = User_clients.objects.order_by('-id').filter(user_id=request.user.id)[0:10]
except User_clients.DoesNotExist:
data = None
return render(request, "client_list.html",{'title':"Client List",'clients':data,'active':'myclients','open':'clients'})
提前非常感谢!