from django.db import models
from smart_selects.db_fields import (
    ChainedForeignKey,
    ChainedManyToManyField,
    GroupedForeignKey,
)
from django.contrib.auth.models import User
# Create your models here.
from mptt.models import MPTTModel, TreeForeignKey
from cms.models import PostCat, Post
from fruit.models import  Product, ProductType

class GenericModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True, null=True)
    updated_at = models.DateTimeField(auto_now=True)

    created_by = models.ForeignKey(User, null=True, editable=False, related_name='%(class)s_created', on_delete=models.SET_NULL)
    modified_by = models.ForeignKey(User, null=True, editable=False, related_name='%(class)s_modified', on_delete=models.SET_NULL)

    class Meta:
        abstract = True



class SearchData(GenericModel, models.Model):
    q = models.CharField(max_length=200, blank=True, default="")
    product_type = TreeForeignKey(ProductType, on_delete=models.SET_NULL, null=True, blank=True)
    content_cat = TreeForeignKey(PostCat, on_delete=models.SET_NULL, null=True, blank=True)
