from django.core.management.base import BaseCommand, CommandError from django.utils import timezone from main.models import ProductsUpdate class Command(BaseCommand): def handle(self, *args, **options): p = ProductsUpdate.objects.last() if not p: p = ProductsUpdate.objects.create(created=timezone.now()) p.created = timezone.now() p.save() self.stdout.write('{}'.format(p.created))