models.py 921 B

12345678910111213141516171819202122
  1. from django.db import models
  2. # Create your models here.
  3. from django.db import models
  4. from django.contrib.auth.models import AbstractUser
  5. # Create your models here.
  6. class AbUser(AbstractUser):
  7. foto = models.ImageField(upload_to='media/')
  8. class Product(models.Model):
  9. name = models.CharField(max_length=255, blank=False, null=False)
  10. date = models.DateTimeField(auto_now_add=True, null=False)
  11. description = models.TextField(max_length=1000, blank=False, null=False)
  12. types = (('Товар', 'Товар'), ('Услуга', 'Услуга'))
  13. type = models.CharField(choices=types, max_length=6)
  14. image = models.ImageField(upload_to='media/', null=True,blank=True)
  15. def __str__(self):
  16. return self.name
  17. class Basket(models.Model):
  18. product = models.ForeignKey('Product', on_delete=models.SET_NULL, null=True)
  19. user = models.ForeignKey('AbUser', on_delete=models.SET_NULL, null=True)