Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ambulance models , used to define tables in a DB
- from django.db import models
- from users.models import CustomUser
- # Create your models here.
- class Ambulance(models.Model):
- driver = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
- number = models.PositiveBigIntegerField(verbose_name="ambulance number plate", unique=True, blank=False, null=False)
- # status = models.CharField(max_length=50,
- # choices=(
- # ("Available", "available"),
- # ("Unavailable", "unavailable"),
- # ("Busy", "busy"),
- # ("Arrived", "arrived"),
- # ("On-Route", "on-route")
- # )
- # )
- latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
- longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
- # will be changed to emergency later
- class AmbulanceRequest(models.Model):
- # user who created request
- user = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
- priority = models.CharField(max_length=10, choices=(
- ("Emergency", "Emergency"),
- ("Routine", "Routine"),
- ))
- emergency_details = models.TextField(null=True, blank=True)
- # hosptal has destination
- hospital = models.ForeignKey("Hospital", on_delete=models.CASCADE)
- detected_address = models.CharField(max_length=255, blank=True)
- STATUS_CHOICES = [
- ('pending', 'Pending'),
- ('assigned', 'Ambulance Assigned'),
- ('completed', 'Completed'),
- ('cancelled', 'Cancelled'),
- ]
- status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
- # automatically detected location
- latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
- longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
- # timestamps
- created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(auto_now=True) # saves after every update
- def __str__(self):
- return f"EmergencyRequest by {self.user.first_name} {self.user.last_name} to {self.hospital.name} ({self.status})"
- class Hospital(models.Model):
- name = models.CharField(max_length=255)
- latitude = models.FloatField(null=True, blank=True)
- longitude = models.FloatField(null=True, blank=True)
- def __str__(self):
- return self.name
Advertisement
Add Comment
Please, Sign In to add comment