This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Airport(models.Model): | |
code = models.CharField(max_length=4) | |
fullname = models.CharField(max_length=50) | |
country = models.CharField(max_length=50) | |
def __str__(self): | |
return self.fullname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightTable(tables.Table): | |
class Meta: | |
model = Flight | |
fields = ('ff_number','ff_from__fullname','ff_from__country','ff_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Airport(models.Model): | |
code = models.CharField(max_length=4) | |
fullname = models.CharField(max_length=50) | |
def __str__(self): | |
return self.fullname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Flight(models.Model): | |
ff_number = models.CharField(max_length=10,verbose_name="Flight Number") | |
ff_company = models.ForeignKey(FlightCo, on_delete=models.CASCADE, verbose_name="Flight Company") | |
ff_from = models.ForeignKey(Airport, on_delete=models.CASCADE, related_name="airport_from", verbose_name="From") | |
ff_to = models.ForeignKey(Airport, on_delete=models.CASCADE, related_name="airport_to", verbose_name="To") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightTable(tables.Table): | |
class Meta: | |
model = Flight | |
class FlightFilter(django_filters.FilterSet): | |
class Meta: | |
model = Flight | |
fields = {"ff_from__fullname": ["icontains"]} | |
label = "Search location or flight number" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightFilter(django_filters.FilterSet): | |
class Meta: | |
model = Flight | |
fields = {"ff_from__fullname": ["icontains"]} | |
label = "Search location or flight number" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightTable(tables.Table): | |
class Meta: | |
model = Flight | |
class FlightFilter(django_filters.FilterSet): | |
class Meta: | |
model = Flight | |
fields = ['ff_from__fullname'] | |
class FlightTableView(SingleTableMixin, FilterView): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlightFilter(django_filters.FilterSet): | |
class Meta: | |
model = Flight | |
fields = ['ff_from'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class LookUpAirport(models.Model): | |
code = models.CharField(max_length=4) | |
fullname = models.CharField(max_length=20) | |
# Create your models here. | |
class FlightCo(models.Model): | |
ff_company_name = models.CharField(max_length=20) | |
ff_company_short = models.CharField(max_length=4,default="AAL") | |
NewerOlder