from django.dispatch import receiver
from django.utils.text import slugify
from django.db.models.signals import post_delete, pre_save

from blog.models import *


def category_create(sender, instance, **kwargs):
    instance.name = instance.name.lower()


pre_save.connect(category_create, sender=Category)


# Create Slug to each new Post before you save to DB.
def slug_create(sender, instance, *args, **kwargs):
    if not instance.slug:
        instance.slug = slugify(instance.author.first_name + "-" + instance.author.last_name + "-" + instance.title)


pre_save.connect(slug_create, sender=Post)


@receiver(post_delete, sender=Post)
def submission_delete(sender, instance, **kwargs):
    instance.image.delete(False)

from django.dispatch import receiver
from django.utils.text import slugify
from django.db.models.signals import post_delete, pre_save

from blog.models import *


def category_create(sender, instance, **kwargs):
    instance.name = instance.name.lower()


pre_save.connect(category_create, sender=Category)


# Create Slug to each new Post before you save to DB.
def slug_create(sender, instance, *args, **kwargs):
    if not instance.slug:
        instance.slug = slugify(instance.author.first_name + "-" + instance.author.last_name + "-" + instance.title)


pre_save.connect(slug_create, sender=Post)


@receiver(post_delete, sender=Post)
def submission_delete(sender, instance, **kwargs):
    instance.image.delete(False)

# Create Slug to each new Post before you save to DB.