我在Django中有2个模型类:
class Notification(models.Model):
receiver = models.ForeignKey(User, null=True, blank=True)
content = models.CharField(max_length=500)
object_id = models.IntegerField(blank=True, null=True)
type = models.TextField(max_length=200, blank=True, null=True)
类通知存储有关用户活动的通知。字段"内容"就像:"欢迎您成功注册商务课程",或者" 5ASC是您的优惠券代码"。字段类型存储对象类型:课程,促销。
class PaymentTransaction(models.Model):
course = models.ForeignKey(Course)
student = models.ForeignKey(User)
PAYMENT_STATUS = ( SUCCESS, FAILURE, PROCESSING)
payment_status = models.CharField(max_length=50, choices=PAYMENT_STATUS, default=PROCESSING)
在通知弹出窗口中,当他点击付费课程然后转到课程详细信息页面并开始学习,当他点击未付课程然后转到课程注册页面,当他点击促销代码然后转到促销代码页< / p>
如何让QuerySet返回Notification和PaymentTransaction表的所有字段,条件是Notification.receiver_id = PaymentTransaction.student_id。 对于每个课程通知,我想获得课程付款状态。我做了:
user = request.user
p_list = PaymentTransaction.objects.filter(student=user)
n_list = Notification.objects.filter(receiver=user).intersection(p_list)
但它确实有效
答案 0 :(得分:0)
我无法理解为什么你这样创建模型但是: 我认为应该是:
class Book:
title = models.CharField(max_length=500)
price = models.FloatField()
class User:
name= models.CharField(max_length=500)
something = models.CharField()
class Book_User:
user = models.ForeignKey(User)
book = models.ForeignKey(User)
detail = models.CharField()
我的意思是什么?只是出现在列表中? 〜&GT;它应该是用户页面中的Book_User列表 〜&GT;问题解决