inital commit
This commit is contained in:
45
equipment/models.py
Normal file
45
equipment/models.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class EquipmentCategory(models.Model):
|
||||
name = models.CharField(max_length=64, unique=True)
|
||||
slug = models.SlugField(max_length=64, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class EquipmentItem(models.Model):
|
||||
vendor = models.ForeignKey("accounts.VendorProfile", on_delete=models.CASCADE, related_name="equipment_items")
|
||||
category = models.ForeignKey(EquipmentCategory, on_delete=models.PROTECT, related_name="items")
|
||||
title = models.CharField(max_length=255)
|
||||
public_id = models.CharField(max_length=64, unique=True)
|
||||
description = models.TextField(blank=True)
|
||||
details = models.JSONField(default=dict, blank=True)
|
||||
location = models.CharField(max_length=255, blank=True)
|
||||
price_per_day = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
is_active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-created_at",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.title} ({self.public_id})"
|
||||
|
||||
|
||||
class EquipmentImage(models.Model):
|
||||
item = models.ForeignKey(EquipmentItem, on_delete=models.CASCADE, related_name="images")
|
||||
image = models.ImageField(upload_to="equipment_images/")
|
||||
alt_text = models.CharField(max_length=255, blank=True)
|
||||
sort_order = models.PositiveIntegerField(default=0)
|
||||
is_primary = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("sort_order", "id")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Image for {self.item.public_id}"
|
||||
Reference in New Issue
Block a user