from django import template

from main.models import *

register = template.Library()


# @register.simple_tag(name="get_sbg")
# @register.simple_tag
# def get_stud_by_group(id):
#     return Students.objects.filter(group__pk=id)

# @register.simple_tag
# def get_stud_by_order(id):
#     return Contracts.objects.filter(orders__pk=id)

@register.simple_tag(name="get_cbs")
def get_contr_by_stud(id):
    return Contracts.objects.filter(client__pk=id).order_by("agreement_date")#[:1]

@register.simple_tag(name="get_cbg")
def get_contracts_by_group(id):
    return Contracts.objects.filter(group__pk=id).order_by('client__surname')
    # return Students.objects.filter(contracts__group__pk=id)

@register.inclusion_tag("main/teg_list_stud.html")
def show_students_by_order(id):
    students = Students.objects.filter(contracts__orders__pk=id)
    return {"objects": students, "id":id}


@register.inclusion_tag("main/teg_list_stud.html")
def show_students_by_group(id):
    students = Students.objects.filter(contracts__group__pk=id)
    return {"objects": students, "id":id}
