Skip to content

Commit

Permalink
Allow searching for drivers in booking admin list page
Browse files Browse the repository at this point in the history
by denormalizing driver values from booking vehicles to booking model.
  • Loading branch information
rtnpro committed May 28, 2019
1 parent 18f2d98 commit 2571f2a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
restart: on-failure

db:
image: postgres:latest
image: postgres:10.8
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
Expand Down
2 changes: 1 addition & 1 deletion opencabs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class BookingAdmin(ExportMixin, admin.ModelAdmin):
list_filter = ('booking_type', 'status', 'travel_date',
'created', 'payment_status', 'payment_method')
search_fields = ('booking_id', 'customer_name', 'customer_mobile',
'travel_date')
'travel_date', 'drivers')
readonly_fields = ('total_fare', 'payment_due', 'payment_done',
'payment_status', 'revenue',
'last_payment_date',)
Expand Down
20 changes: 20 additions & 0 deletions opencabs/migrations/0028_booking_drivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2019-05-28 13:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('opencabs', '0027_auto_20190210_1507'),
]

operations = [
migrations.AddField(
model_name='booking',
name='drivers',
field=models.CharField(blank=True, default='', max_length=500),
),
]
9 changes: 9 additions & 0 deletions opencabs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class Booking(models.Model):
created = models.DateTimeField(auto_now_add=True, blank=True)
last_updated = models.DateTimeField(auto_now=True, blank=True)

drivers = models.CharField(max_length=500, default="", blank=True)

def __str__(self):
return self.booking_id

Expand Down Expand Up @@ -476,6 +478,13 @@ def request(self):
self.save()
self.send_trip_status_to_customer()

def update_drivers(self):
drivers = ""
for vehicle in self.bookingvehicle_set.all().select_related('driver'):
if vehicle.driver:
drivers += vehicle.driver.name
self.drivers = drivers
self.save()

class BookingVehicle(models.Model):
booking = models.ForeignKey(Booking)
Expand Down
7 changes: 7 additions & 0 deletions opencabs/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

from finance.models import Payment

from .models import BookingVehicle


@receiver([post_save, post_delete], sender=Payment)
def update_booking_payment_info(sender, instance, **kwargs):
if instance.item_content_type.app_label == 'opencabs' and \
instance.item_content_type.model == 'booking':
if instance.item_object:
instance.item_object.save()


@receiver([post_save, post_delete], sender=BookingVehicle)
def update_booking_drivers(sender, instance, **kwargs):
instance.booking.update_drivers()

0 comments on commit 2571f2a

Please sign in to comment.