import django
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone


class AdvUser(AbstractUser):
    avatar = models.ImageField(upload_to='images/profiles', verbose_name='Аватар')


class Service(models.Model):
    name = models.CharField(max_length=255, blank=False, null=False, verbose_name='Наименование')
    description = models.TextField(max_length=500, blank=False, null=False, verbose_name='Описание')
    image = models.ImageField(upload_to='images/products', verbose_name='Изображение')
    publish_date = models.DateTimeField(verbose_name='Дата и время добавления', default=django.utils.timezone.now)

    types = (
        ('Товар', 'Товар'),
        ('Услуга', 'Услуга')
    )

    type = models.CharField(max_length=10, choices=types, blank=False, null=False, verbose_name='Тип')

    def __str__(self):
        return self.name


class OrderedService(models.Model):
    user = models.ForeignKey(AdvUser, on_delete=models.CASCADE)
    service = models.ForeignKey(Service, on_delete=models.CASCADE)

