【发布时间】:2017-05-30 15:41:43
【问题描述】:
我在 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)
在弹出的通知中,点击付费课程进入课程详情页面开始学习,点击未付费课程进入课程注册页面,点击促销代码进入促销代码页面
如何让 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)
但是没有用
【问题讨论】:
标签: django-models django-queryset