try doing custom filter spec things to make unique routes stops filtered
This commit is contained in:
parent
729cee52d5
commit
8207b33a30
|
@ -2,6 +2,22 @@ from django.contrib.gis import admin
|
||||||
from django import forms
|
from django import forms
|
||||||
from mumbai.models import *
|
from mumbai.models import *
|
||||||
from django.contrib.contenttypes import generic
|
from django.contrib.contenttypes import generic
|
||||||
|
from django.contrib.admin.filterspecs import FilterSpec, RelatedFilterSpec
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFilterSpec(RelatedFilterSpec):
|
||||||
|
def __init__(self, f, *args, **kwargs):
|
||||||
|
super(CustomFilterSpec, self).__init__(f, *args, **kwargs)
|
||||||
|
instance = f
|
||||||
|
stop_choices = instance.get_stop_choices()
|
||||||
|
CHOICES = (
|
||||||
|
(item.id, item.name) for item in stop_choices
|
||||||
|
)
|
||||||
|
self.lookup_choices = CHOICES
|
||||||
|
|
||||||
|
|
||||||
|
FilterSpec.filter_specs.insert(0, (lambda f: bool(f.rel and hasattr(f, 'custom_filter_spec')), CustomFilterSpec))
|
||||||
|
|
||||||
|
|
||||||
class RouteScheduleInline(admin.StackedInline):
|
class RouteScheduleInline(admin.StackedInline):
|
||||||
model = RouteSchedule
|
model = RouteSchedule
|
||||||
|
|
|
@ -7,6 +7,8 @@ from django.db import connection
|
||||||
import json
|
import json
|
||||||
from django.contrib.gis.measure import D
|
from django.contrib.gis.measure import D
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
STOP_CHOICES = ( ('U','Up'),
|
STOP_CHOICES = ( ('U','Up'),
|
||||||
('D', 'Down'),
|
('D', 'Down'),
|
||||||
)
|
)
|
||||||
|
@ -301,7 +303,8 @@ class UniqueRoute(models.Model):
|
||||||
to_stop = models.ForeignKey(Stop, related_name="unique_routes_to")
|
to_stop = models.ForeignKey(Stop, related_name="unique_routes_to")
|
||||||
distance = models.FloatField(blank=True, null=True)
|
distance = models.FloatField(blank=True, null=True)
|
||||||
is_full = models.BooleanField()
|
is_full = models.BooleanField()
|
||||||
|
from_stop.custom_filter_spec = True # this is used to identify the fields which use the custom filter
|
||||||
|
to_stop.custom_filter_spec = True # this is used to identify the fields which use the custom filter
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'Atlas'
|
verbose_name = 'Atlas'
|
||||||
verbose_name_plural = 'Atlas'
|
verbose_name_plural = 'Atlas'
|
||||||
|
@ -310,7 +313,7 @@ class UniqueRoute(models.Model):
|
||||||
return "%s: %s to %s" % (self.route.alias, self.from_stop_txt, self.to_stop_txt)
|
return "%s: %s to %s" % (self.route.alias, self.from_stop_txt, self.to_stop_txt)
|
||||||
|
|
||||||
def get_stop_choices(self):
|
def get_stop_choices(self):
|
||||||
return Stop.objects.filter(routedetail__route=self.instance.route).order_by('routedetail')
|
return Stop.objects.filter(routedetail__route=self.route).order_by('routedetail')
|
||||||
|
|
||||||
class RouteSchedule(models.Model):
|
class RouteSchedule(models.Model):
|
||||||
unique_route = models.ForeignKey(UniqueRoute)
|
unique_route = models.ForeignKey(UniqueRoute)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user