Skip to content

Instantly share code, notes, and snippets.

@ktechmidas
Created December 4, 2020 09:05
Show Gist options
  • Save ktechmidas/8aba5bd60fce85d7f809a7521dee7b08 to your computer and use it in GitHub Desktop.
Save ktechmidas/8aba5bd60fce85d7f809a7521dee7b08 to your computer and use it in GitHub Desktop.
from django.shortcuts import render
from django.views.generic import ListView,View
import django_tables2 as tables
from .models import Flight,FlightCo
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin
import django_filters
# Create your views here.
class Index(View):
template = 'pages/test.html'
def get(self, request):
return render(request, self.template)
class About(View):
template = 'pages/about.html'
def get(self, request):
return render(request, self.template)
class FlightTable(tables.Table):
from_fullname = tables.Column(accessor="ff_from.fullname")
from_country = tables.Column(accessor="ff_from.country")
to_fullname = tables.Column(accessor="ff_to.fullname")
class Meta:
model = Flight
fields = ("ff_number", "from_fullname", "from_country", "to_fullname")
class FlightFilter(django_filters.FilterSet):
full_name = django_filters.CharFilter(field_name="ff_from__fullname", label="Search location", lookup_expr="icontains")
class Meta:
model = Flight
fields = ["full_name"]
class FlightTableView(SingleTableMixin, FilterView):
table_class = FlightTable
template_name = 'pages/flightlist.html'
filterset_class = FlightFilter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment