Retrieving unique results in Django queryset based on column contents -


I'm not sure that the title has any meaning, but this is the question.

References: I want to track the students entering the class, so at any time I can know who is inside the class. I also want to keep track, for example, how many times one The student has entered the class, this is a hypothetical example which is close to what I want to achieve.

I have prepared the class and each entry has student (foreigner), verb (entry, departure) and date.

My question is how to get the students coming in at present (i.e. their entries' date is after the date of their leave action, or the date of the leave), and how a specified date


Edit : On better consideration, I should add that there are more than one class

My first attempt was something like this:

students_in = Classroom.objects.filter (class__ exact = 1, action__exact = '1') students_out = Classroom.objects.filter where the student has operations

(class_anissimation = 1, verb_translation = '0'). Values_list ('student', flat = true) is in students_now = students_in.exclude (student__in = students_out) / code> == 1, 0 is out.

It again provides wrong data as soon as a student leaves the class and enters again, he is listed twice in the students_now queries, because the two 'entrance' And there is a 'holiday' besides, I can not see specific date ranges to see if the date of entry of the student is more than the date of their leave.

To check the field based on the value of another field, use the operator.

from d students_in_classroom_now = student.objects.filter (leave__gte = f ('ant'))

All students in the room at a certain time To get:

  import datetime start_time = datetime.datetime (2010, 1, 21, 10, 0, 0) # 10am tomorrow students_in_classroom_then = Student.objects.filter (enter__lte = start_time , Leave__gte = start_time)  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -