Skip to content

Instantly share code, notes, and snippets.

@JoeyCodinja
Last active September 28, 2020 13:45
Show Gist options
  • Save JoeyCodinja/35a89b9af0596a3d7223b65701b746fd to your computer and use it in GitHub Desktop.
Save JoeyCodinja/35a89b9af0596a3d7223b65701b746fd to your computer and use it in GitHub Desktop.
Fetch Script for Policies omitting vehicle registration number
from django.db.models import Q
query = Q(quotation__vehicle__license_plate="") | Q(quotation__vehicle__license_plate=None)
POLICYS_IN_QUESTION = Policy.objects.filter(query)
f = open('cert-no-show-reg-number.txt', 'w')
for policy in POLICYS_IN_QUESTION:
f.write("== {} ==\n".format(policy.policy_number))
try:
quotation_vehicle = policy.quotation.vehicle
risk_vehicle = policy.risk.vehicle
f.write("--Quotation Vehicle Information--\n"
"Registration Number: {}\n"
"VIN: {}\n".format(quotation_vehicle.license_plate, quotation_vehicle.vin))
f.write("--Risk (Policy) Vehicle Information--\n"
"Registration Number: {}\n"
"VIN: {}\n".format(risk_vehicle.license_plate, risk_vehicle.vin))
except Policy.quotation.RelatedObjectDoesNotExist as e:
print "Policy in question doesn't have a quotation :/ Strange"
f.write('== END ==')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment