A Model Class

part of salon class in my booking project

python intermediate July 12, 2025
code.python 13 lines
class Salon(TimestampedModel):
    """Model for a salon with contact, location, and amenities."""
    owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
                              related_name='salons_owned', verbose_name='مدیریت‌کننده')
    name = models.CharField('نام سالن', max_length=100)
    slug = models.SlugField('شناسه URL', max_length=120, unique=True, blank=True)
    address = models.CharField('آدرس', max_length=200)
    phone = models.CharField('شماره تلفن', max_length=20, blank=True)
    email = models.EmailField('ایمیل', blank=True)
    website = models.URLField('وب‌سایت', blank=True)
    image = models.ImageField('عکس سالن', upload_to='salons/', blank=True, null=True)
    amenities = models.ManyToManyField(Amenity, blank=True,
                                       related_name='salons', verbose_name='امکانات')
    latitude = models.DecimalField('عرض جغرافیایی', max_digits=9, decimal_places=6,
                                   blank=True, null=True)
    longitude = models.DecimalField('طول جغرافیایی', max_digits=9, decimal_places=6,
                                    blank=True, null=True)
    is_active = models.BooleanField('فعال', default=True)
    average_rating = models.DecimalField('میانگین امتیاز', max_digits=3, decimal_places=2,
                                         default=0,
                                         validators=[MinValueValidator(0), MaxValueValidator(5)])
    rating_count = models.PositiveIntegerField('تعداد امتیازها', default=0)

    objects = models.Manager()
    active_objects = ActiveManager()

Dependencies