Skip to content

Instantly share code, notes, and snippets.

@volgoweb
Created February 11, 2020 08:29
Show Gist options
  • Save volgoweb/ad9b893a38611de3348ec2e99d9f6389 to your computer and use it in GitHub Desktop.
Save volgoweb/ad9b893a38611de3348ec2e99d9f6389 to your computer and use it in GitHub Desktop.
refactor unpublishing the posts
# .. import section ..
class Post(models.Model):
author = models.ForeignKey(CustomUserModel)
title = models.CharField(max_length=200)
text = models.CharField(max_length=15000)
is_published = models.BooleanField()
# .. import section ..
def unpublish_posts(request):
ids = request.POST.get('ids').split(',')
for post in Post.objects.filter(ids__in=ids):
if post.is_published:
send_email(
'Notification',
'Your article has been unpublished!',
'from@example.com',
[post.author.email],
fail_silently=False,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment