Created
February 11, 2020 08:29
-
-
Save volgoweb/ad9b893a38611de3348ec2e99d9f6389 to your computer and use it in GitHub Desktop.
refactor unpublishing the posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .. 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .. 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!', | |
'[email protected]', | |
[post.author.email], | |
fail_silently=False, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment