from datetime import timedelta from django.core.management.base import BaseCommand from django.db.models import F from apps.payment.models import CoursePayment class Command(BaseCommand): help = 'Fill payment.access_expire where it is not filled' def handle(self, *args, **options): for payment in CoursePayment.objects.filter(access_expire__isnull=True): payment.access_expire = payment.created_at.date() + timedelta(days=payment.course.access_duration) payment.save()