service categories
This commit is contained in:
parent
79a8c6f280
commit
17b6c4c9ee
6 changed files with 154 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.text import slugify
|
||||
|
||||
|
||||
def validate_image_size(value):
|
||||
|
@ -8,6 +9,39 @@ def validate_image_size(value):
|
|||
raise ValidationError("Maximum file size is 1MB")
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
slug = models.SlugField(unique=True)
|
||||
parent = models.ForeignKey(
|
||||
"self", on_delete=models.CASCADE, null=True, blank=True, related_name="children"
|
||||
)
|
||||
description = models.TextField(blank=True)
|
||||
order = models.IntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Categories"
|
||||
ordering = ["order", "name"]
|
||||
|
||||
def __str__(self):
|
||||
if self.parent:
|
||||
return f"{self.parent} > {self.name}"
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
self.slug = slugify(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def full_path(self):
|
||||
path = [self.name]
|
||||
parent = self.parent
|
||||
while parent:
|
||||
path.append(parent.name)
|
||||
parent = parent.parent
|
||||
return " > ".join(reversed(path))
|
||||
|
||||
|
||||
class CloudProvider(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.TextField(blank=True)
|
||||
|
@ -47,6 +81,7 @@ class Service(models.Model):
|
|||
description = models.TextField()
|
||||
cloud_provider = models.ForeignKey(CloudProvider, on_delete=models.CASCADE)
|
||||
service_level = models.ForeignKey(ServiceLevel, on_delete=models.CASCADE)
|
||||
categories = models.ManyToManyField(Category, related_name="services")
|
||||
countries = models.ManyToManyField(Country)
|
||||
price = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
features = models.TextField()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue