python - Pre save a slug on creation results in a 'LogEntry' object has no attribute pre_save -


i trying auto generate slug on creation of object in django.

my method use pre_save signal, using @receiver call.

when create new entry in django admin, 'logentry' object has no attribute 'title'.

i made admin model looks this:

class countryadmin(admin.modeladmin):     fields = ('title', 'is_visible') 

i have following model.py code country object:

class country(models.model):     title = models.charfield(max_length=200)     alias = models.slugfield(max_length=200)     is_visible = models.booleanfield(default=false)      def __str__(self):         return self.title      @staticmethod     def get_all():         return country.objects.filter(is_visible = true).order_by('title')      @receiver(pre_save)     def country_presave_callback(sender, instance, *args, **kwargs):         instance.alias = slugify(instance.title) 

how modify code slugs automatically created on creation of objects?

you should pass sender model @receiver decorator:

@receiver(pre_save, sender=country) def country_presave_callback(sender, instance, *args, **kwargs):     ... 

in case callback called when instance of country saved. without sender argument callback called all models.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -