<gh_stars>0
from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from django.utils import timezone
from django.contrib.auth.models import User


class Item(models.Model):
    LABELS = (
        ("BestSeller", "BestSeller"),
        ("New", "New"),
        ("Spicy🔥", "Spicy🔥"),
    )

    LABEL_COLOUR = (
        ("danger", "danger"),
        ("success", "success"),
        ("primary", "primary"),
        ("info", "info"),
    )
    title = models.CharField(max_length=150)
    description = models.CharField(max_length=250, blank=True)
    price = models.FloatField()
    pieces = models.IntegerField(default=6)
    instructions = models.CharField(max_length=250, default="Jain Option Available")
    image = models.ImageField(default="default.png", upload_to="images/")
    labels = models.CharField(max_length=25, choices=LABELS, blank=True)
    label_colour = models.CharField(max_length=15, choices=LABEL_COLOUR, blank=True)
    slug = models.SlugField(default="sushi_name")
    created_by = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("main:dishes", kwargs={"slug": self.slug})

    def get_add_to_cart_url(self):
        return reverse("main:add-to-cart", kwargs={"slug": self.slug})

    def get_item_delete_url(self):
        return reverse("main:item-delete", kwargs={"slug": self.slug})

    def get_update_item_url(self):
        return reverse("main:item-update", kwargs={"slug": self.slug})


class Reviews(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    item = models.ForeignKey(Item, on_delete=models.CASCADE)
    rslug = models.SlugField()
    review = models.TextField()
    posted_on = models.DateField(default=timezone.now)

    class Meta:
        verbose_name = "Review"
        verbose_name_plural = "Reviews"

    def __str__(self):
        return self.review


class CartItems(models.Model):
    ORDER_STATUS = (("Active", "Active"), ("Delivered", "Delivered"))
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    item = models.ForeignKey(Item, on_delete=models.CASCADE)
    ordered = models.BooleanField(default=False)
    quantity = models.IntegerField(default=1)
    ordered_date = models.DateField(default=timezone.now)
    status = models.CharField(max_length=20, choices=ORDER_STATUS, default="Active")
    delivery_date = models.DateField(default=timezone.now)

    class Meta:
        verbose_name = "Cart Item"
        verbose_name_plural = "Cart Items"

    def __str__(self):
        return self.item.title

    def get_remove_from_cart_url(self):
        return reverse("main:remove-from-cart", kwargs={"pk": self.pk})

    def update_status_url(self):
        return reverse("main:update_status", kwargs={"pk": self.pk})

from django.db import models
from django.conf import settings
from django.shortcuts import reverse
from django.utils import timezone
from django.contrib.auth.models import User


class Item(models.Model):
    LABELS = (
        ("BestSeller", "BestSeller"),
        ("New", "New"),
        ("Spicy🔥", "Spicy🔥"),
    )

    LABEL_COLOUR = (
        ("danger", "danger"),
        ("success", "success"),
        ("primary", "primary"),
        ("info", "info"),
    )
    title = models.CharField(max_length=150)
    description = models.CharField(max_length=250, blank=True)
    price = models.FloatField()
    pieces = models.IntegerField(default=6)
    instructions = models.CharField(max_length=250, default="Jain Option Available")
    image = models.ImageField(default="default.png", upload_to="images/")
    labels = models.CharField(max_length=25, choices=LABELS, blank=True)
    label_colour = models.CharField(max_length=15, choices=LABEL_COLOUR, blank=True)
    slug = models.SlugField(default="sushi_name")
    created_by = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("main:dishes", kwargs={"slug": self.slug})

    def get_add_to_cart_url(self):
        return reverse("main:add-to-cart", kwargs={"slug": self.slug})

    def get_item_delete_url(self):
        return reverse("main:item-delete", kwargs={"slug": self.slug})

    def get_update_item_url(self):
        return reverse("main:item-update", kwargs={"slug": self.slug})


class Reviews(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    item = models.ForeignKey(Item, on_delete=models.CASCADE)
    rslug = models.SlugField()
    review = models.TextField()
    posted_on = models.DateField(default=timezone.now)

    class Meta:
        verbose_name = "Review"
        verbose_name_plural = "Reviews"

    def __str__(self):
        return self.review


class CartItems(models.Model):
    ORDER_STATUS = (("Active", "Active"), ("Delivered", "Delivered"))
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    item = models.ForeignKey(Item, on_delete=models.CASCADE)
    ordered = models.BooleanField(default=False)
    quantity = models.IntegerField(default=1)
    ordered_date = models.DateField(default=timezone.now)
    status = models.CharField(max_length=20, choices=ORDER_STATUS, default="Active")
    delivery_date = models.DateField(default=timezone.now)

    class Meta:
        verbose_name = "Cart Item"
        verbose_name_plural = "Cart Items"

    def __str__(self):
        return self.item.title

    def get_remove_from_cart_url(self):
        return reverse("main:remove-from-cart", kwargs={"pk": self.pk})

    def update_status_url(self):
        return reverse("main:update_status", kwargs={"pk": self.pk})