# Path: core/models.py
# class Event(models.Model):
# 
#     class Meta:
#         verbose_name = _('Actividad')
# 
#     event_name = models.TextField(
#         verbose_name=_('Nombre actividad'))
#     event_start = models.DateField(
#         verbose_name=_('Fecha inicio'))
#     event_end = models.DateField(
#         verbose_name=_('Fecha fin'))
#     comment = models.TextField(
#         verbose_name=_('Observaciones'), blank=True, default='')
# 
# class Group(models.Model):
# 
#     class Meta:
#         verbose_name = _('Grupo')
# 
#     group_name = models.TextField(verbose_name=_('Nombre grupo'))
#     project = models.ForeignKey(
#         Project, on_delete=models.CASCADE, default=None, null=True, verbose_name=_('Proyecto'))
# 
#     def __str__(self):
#         return '{}'.format(self.id)
# 
# class Project(models.Model):
# 
#     class Meta:
#         verbose_name = _('Proyecto')
# 
#     project_name = models.TextField(
#         verbose_name=_('Nombre proyecto'))
#     date_start = models.DateField(
#         verbose_name=_('Fecha inicio'))
#     date_end = models.DateField(
#         verbose_name=('Fecha fin'))
#     comment = models.TextField(
#         verbose_name=_('Observaciones'), blank=True, default='')
# 
#     def __str__(self):
#         return '{}'.format(self.project_name)


from django import forms
from django.db import models
from django.db.models import Q
from django.db.models import Value as V
from django.db.models.functions import Concat
from django.utils.translation import ugettext_lazy as _
from core.models import Event, Group, Project
import django_filters

    q = django_filters.CharFilter(
        label=_('Nombre'),
        name='name',
        method='custom_filter',
        widget=forms.TextInput(attrs={'placeholder': _('Nombre')}),
    )

    def custom_filter(self, queryset, name, value):
        return queryset.annotate(
            full_name=Concat('name', V(' '), 'surname',
                             output_field=models.TextField())).filter(Q(full_name__icontains=value))


class FromPersonFilter(django_filters.FilterSet):

    q = django_filters.CharFilter(
        label=_('Nombre'), name='person__name', method='custom_filter')

    def custom_filter(self, queryset, name, value):
        return queryset.annotate(
            full_name=Concat('person__name', V(' '), 'person__surname',
                             output_field=models.TextField())).filter(Q(full_name__icontains=value))


class GroupFilter(django_filters.FilterSet):

    q = django_filters.CharFilter(name='group_name', method='custom_filter')

    class Meta:

# Path: core/models.py
# class Event(models.Model):
# 
#     class Meta:
#         verbose_name = _('Actividad')
# 
#     event_name = models.TextField(
#         verbose_name=_('Nombre actividad'))
#     event_start = models.DateField(
#         verbose_name=_('Fecha inicio'))
#     event_end = models.DateField(
#         verbose_name=_('Fecha fin'))
#     comment = models.TextField(
#         verbose_name=_('Observaciones'), blank=True, default='')
# 
# class Group(models.Model):
# 
#     class Meta:
#         verbose_name = _('Grupo')
# 
#     group_name = models.TextField(verbose_name=_('Nombre grupo'))
#     project = models.ForeignKey(
#         Project, on_delete=models.CASCADE, default=None, null=True, verbose_name=_('Proyecto'))
# 
#     def __str__(self):
#         return '{}'.format(self.id)
# 
# class Project(models.Model):
# 
#     class Meta:
#         verbose_name = _('Proyecto')
# 
#     project_name = models.TextField(
#         verbose_name=_('Nombre proyecto'))
#     date_start = models.DateField(
#         verbose_name=_('Fecha inicio'))
#     date_end = models.DateField(
#         verbose_name=('Fecha fin'))
#     comment = models.TextField(
#         verbose_name=_('Observaciones'), blank=True, default='')
# 
#     def __str__(self):
#         return '{}'.format(self.project_name)


# Path: webapp/filters.py
from django import forms
from django.db import models
from django.db.models import Q
from django.db.models import Value as V
from django.db.models.functions import Concat
from django.utils.translation import ugettext_lazy as _
from core.models import Event, Group, Project
import django_filters


    q = django_filters.CharFilter(
        label=_('Nombre'),
        name='name',
        method='custom_filter',
        widget=forms.TextInput(attrs={'placeholder': _('Nombre')}),
    )

    def custom_filter(self, queryset, name, value):
        return queryset.annotate(
            full_name=Concat('name', V(' '), 'surname',
                             output_field=models.TextField())).filter(Q(full_name__icontains=value))


class FromPersonFilter(django_filters.FilterSet):

    q = django_filters.CharFilter(
        label=_('Nombre'), name='person__name', method='custom_filter')

    def custom_filter(self, queryset, name, value):
        return queryset.annotate(
            full_name=Concat('person__name', V(' '), 'person__surname',
                             output_field=models.TextField())).filter(Q(full_name__icontains=value))


class GroupFilter(django_filters.FilterSet):

    q = django_filters.CharFilter(name='group_name', method='custom_filter')

    class Meta:

        model = Group