from django.db import models
from django.contrib.auth.models import User

class Category(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField(blank=True, null=True)

    def __str__(self):
        return self.name

class UserMenu(models.Model):
    title = models.CharField(max_length=100)
    category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='user_menus')  # Assuming each menu belongs to one category
    order = models.IntegerField(default=0)
    description = models.TextField()
    icon = models.CharField(max_length=50, blank=True, null=True)
    image = models.ImageField(upload_to='media/images/menu/', null=True, blank=True)  # Changed 'media/images/' to 'user_menu_images/' for clarity
    url = models.CharField(max_length=200, blank=True, null=True)
    url_text = models.CharField(max_length=50, blank=True, null=True)


    def __str__(self):
        return self.title

    class Meta:
        ordering = ['category', 'order']  # Orders by category first, then by the order field within each category


