def save(self, *args, **kwargs):
from bakery import tasks<EOL>from django.contrib.contenttypes.models import ContentType<EOL>if not kwargs.pop('<STR_LIT>', True):<EOL><INDENT>super(AutoPublishingBuildableModel, self).save(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>preexisting = self.__class__.objects.get(pk=self.pk)<EOL><DEDENT>except self.__class__.DoesNotExist:<EOL><INDENT>preexisting = None<EOL><DEDENT>if not preexisting:<EOL><INDENT>if self.get_publication_status():<EOL><INDENT>action = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>action = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not self.get_publication_status() andpreexisting.get_publication_status():<EOL><INDENT>action = '<STR_LIT>'<EOL><DEDENT>elif self.get_publication_status():<EOL><INDENT>action = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>action = None<EOL><DEDENT><DEDENT>with transaction.atomic():<EOL><INDENT>super(AutoPublishingBuildableModel, self).save(*args, **kwargs)<EOL><DEDENT>ct = ContentType.objects.get_for_model(self.__class__)<EOL>if action == '<STR_LIT>':<EOL><INDENT>tasks.publish_object.delay(ct.pk, self.pk)<EOL><DEDENT>elif action == '<STR_LIT>':<EOL><INDENT>tasks.unpublish_object.delay(ct.pk, self.pk)<EOL><DEDENT><DEDENT>
A custom save that publishes or unpublishes the object where
appropriate.

Save with keyword argument obj.save(publish=False) to skip the process.