0% found this document useful (0 votes)
3 views

avtoticket

The document defines a Django data model for a transportation system, including classes for Discounts, Orders, Notifications, Routes, Tickets, Order Items, Seats, Stations, Regions, Route Stations, Transports, Reviews, and Admins. Each class includes various fields and relationships to represent the structure and functionality of the system. The models encompass aspects such as discount types, order statuses, transport types, and user roles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

avtoticket

The document defines a Django data model for a transportation system, including classes for Discounts, Orders, Notifications, Routes, Tickets, Order Items, Seats, Stations, Regions, Route Stations, Transports, Reviews, and Admins. Each class includes various fields and relationships to represent the structure and functionality of the system. The models encompass aspects such as discount types, order statuses, transport types, and user roles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

from django.

db import models

# Discounts
class Discount(models.Model):
DISCOUNT_TYPES = [
('percentage', 'Percentage'),
('fixed', 'Fixed'),
]
code = models.CharField(max_length=50, unique=True)
discount_type = models.CharField(max_length=20, choices=DISCOUNT_TYPES)
discount_value = models.DecimalField(max_digits=10, decimal_places=2)
valid_from = models.DateTimeField()
valid_to = models.DateTimeField()

def __str__(self):
return self.code

# Orders
class Order(models.Model):
STATUS_CHOICES = [
('pending', 'Pending'),
('paid', 'Paid'),
('cancelled', 'Cancelled'),
]
email = models.EmailField()
phone_number = models.CharField(max_length=20)
payment_date = models.DateTimeField()
card_number = models.BigIntegerField()
amount = models.BigIntegerField()
status = models.CharField(max_length=20, choices=STATUS_CHOICES)

def __str__(self):
return f"Order {self.id} - {self.status}"

# Notifications
class Notification(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
message = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
is_read = models.BooleanField(default=False)

# Routes
class Route(models.Model):
transport = models.ForeignKey('Transport', on_delete=models.CASCADE)
start_location = models.CharField(max_length=255)
end_location = models.CharField(max_length=255)
departure_time = models.DateTimeField()
arrival_time = models.DateTimeField()
price = models.DecimalField(max_digits=10, decimal_places=2)
platform_number = models.BigIntegerField()
driver_id = models.BigIntegerField()

def __str__(self):
return f"Route {self.id} ({self.start_location} -> {self.end_location})"

# Tickets
class Ticket(models.Model):
STATUS_CHOICES = [
('booked', 'Booked'),
('cancelled', 'Cancelled'),
]
route = models.ForeignKey(Route, on_delete=models.CASCADE)
seat_number = models.CharField(max_length=10)
status = models.CharField(max_length=20, choices=STATUS_CHOICES)
created_at = models.DateTimeField(auto_now_add=True)

# Order Items
class OrderItem(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE,
related_name='items')
ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)

# Seats
class Seat(models.Model):
route = models.ForeignKey(Route, on_delete=models.CASCADE)
seat_number = models.CharField(max_length=10)
is_available = models.BooleanField(default=True)

# Stations
class Station(models.Model):
STATION_TYPE_CHOICES = [
('departure', 'Departure'),
('arrival', 'Arrival'),
]
name = models.CharField(max_length=255)
location = models.CharField(max_length=255)
type = models.CharField(max_length=20, choices=STATION_TYPE_CHOICES)
region = models.ForeignKey('Region', on_delete=models.CASCADE)

# Regions
class Region(models.Model):
name = models.CharField(max_length=255)

def __str__(self):
return self.name

# Route Stations
class RouteStation(models.Model):
route = models.ForeignKey(Route, on_delete=models.CASCADE)
station = models.ForeignKey(Station, on_delete=models.CASCADE)
arrival_time = models.DateTimeField()
departure_time = models.DateTimeField()

# Transports
class Transport(models.Model):
TRANSPORT_TYPES = [
('bus', 'Bus'),
('train', 'Train'),
('plane', 'Plane'),
]
type = models.CharField(max_length=20, choices=TRANSPORT_TYPES)
name = models.CharField(max_length=255)
capacity = models.BigIntegerField()
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.name
# Reviews
class Review(models.Model):
route = models.ForeignKey(Route, on_delete=models.CASCADE)
rating = models.IntegerField()
comment = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
order = models.ForeignKey(Order, on_delete=models.CASCADE)

# Admins
class Admin(models.Model):
ROLE_CHOICES = [
('superadmin', 'Super Admin'),
('manager', 'Manager'),
]
fullname = models.CharField(max_length=255)
phone_number = models.BigIntegerField()
username = models.CharField(max_length=100, unique=True)
email = models.EmailField()
password = models.CharField(max_length=255)
role = models.CharField(max_length=20, choices=ROLE_CHOICES)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.username

You might also like