models.py
class BuyNotes(models.Model): student = models.ForeignKey(to=Student, on_delete=models.SET_NULL, null=True) note = models.ForeignKey(to=Notes, on_delete=models.SET_NULL, null=True) buy_at = models.DateField(auto_now_add=True) amount = models.IntegerField(default=0, null=True) class Meta: unique_together = [['note', 'student']] views.py
def allNotesStudent(request): user = User.objects.get(username=request.session['user']) student = Student.objects.get(user=user) buy_notes = BuyNotes.objects.filter(student=student).get(note) I know last line is wrong. how to get all objects of note that current login student bought
https://stackoverflow.com/questions/66666811/how-to-get-nested-objects-in-django March 17, 2021 at 12:01PM
没有评论:
发表评论