Добрый день! Мне нужно сделать сравнительный запрос. Я реализовал этот фрагмент в своем представлении, но он возвращает мне ошибку:
TypeError в / listsalocate / QuerySet.annotate () получил невыраженное выражение (я): 40.
Вот мой код:
Модели
class Room (models.Model):
block = models.ForeignKey (Block, on_delete = models.PROTECT)
room = models.CharField ('Room:', unique = True, max_length = 50)
capmax = models.IntegerField ('Maximum Cap:')
available = models.BooleanField ('Available', default = True)
busy = models.BooleanField ('Busy', default = False)
internet = models.BooleanField ('Internet', default = False)
projector = models.BooleanField ('Projector', default = True)
computer = models.BooleanField ('Computer', default = False)
class Estclass (models.Model):
estclass = models.CharField ('Class', max_length = 20)
course = models.CharField ('Course', null = False, max_length = 50)
period = models.CharField ('Period', null = False, max_length = 50)
discipline = models.CharField ('Discipline', max_length = 50)
estudents = models.IntegerField ('Qty')
professor = models.CharField ('Professor', max_length = 50)
allocated = models.BooleanField ('Allocated', default = False)
internet = models.BooleanField ('Internet', default = False)
projector = models.BooleanField ('Projector', default = False)
computer = models.BooleanField ('Computer', default = False)
class Allocate (models.Model):
date = models.DateField ('Date', auto_now = True, blank = True)
days = [
('Monday', 'Monday'),
('Tuesday', 'Tuesday'),
('Wednesday', 'Wednesday'),
('Thursday', 'Thursday'),
('Friday', 'Friday'),
('Saturday', 'Saturday'),
]
day = models.CharField ('Day', max_length = 11, choices = days,
default = 'Confirming')
time = models.ForeignKey (Time, on_delete = models.CASCADE)
estclass = models.ForeignKey (Class, on_delete = models.SET ())
room = models.ForeignKey (Room, on_delete = models.SET ())
выдержка из моего взгляда методом
...
room = Allocate.objects.select_related ('room'). values (room = room.capmax)
capmax = int (room)
estclass = Allocate.objects.select_related ('estclass'). values (estclass = estclass.estudents)
capmax = int (estclass)
if estclass > room:
messages.info (request, 'Number of students greater than capacity')
return redirect ('allocate: listalocate')
...
Может ли кто-нибудь мне помочь?