Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 4. License
- class Driver(models.Model):
- first_name = models.CharField(max_length=50)
- last_name = models.CharField(max_length=50)
- class DrivingLicense(models.Model):
- license_number = models.CharField(max_length=10, unique=True)
- issue_date = models.DateField()
- driver = models.OneToOne("Driver", on_delete=models.CASCADE)
- def __str__(self):
- expiration_date = self.issue_date + timedelta(days=365)
- return f"License with id: {self.id} expires on {expiration_date}!
- def calculate_licenses_expiration_dates():
- licenses = DrivingLicense.objects.order_by('-license_number')
- return "\n".join(str(l) for l in licenses)
- def get_drivers_with_expired_licenses(due_date):
- expiration_cutoff_date = due_date - timedelta(days=365)
- expired_drivers = Driver.objects.filter(DrivingLicense__issue_date__gt=expiration_cutoff_date)
- return expired_drivers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement