social-scheduler/social_scheduler/web/posts/management/commands/post.py

21 lines
677 B
Python

from datetime import datetime
from django.core.management.base import BaseCommand
from social_scheduler.web.posts.models import Post, Image
class Command(BaseCommand):
help = 'Post all scheduled posts.'
def handle(self, *args, **options):
posts = Post.objects.filter(
publication_date__lte=datetime.now().astimezone(),
posted=False)
for post in posts:
print(post.id)
images = Image.objects.filter(post_id=post.id)
self.stdout.write(self.style.SUCCESS(post.message))
imgs = {img.path.path: img.caption for img in images}
self.stdout.write(self.style.SUCCESS(imgs))