[Answer]-Execute Django shell command as cron

1👍

Take a look at Custom management commands for django.

As a basic example:

from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from perfil.models import *

class Command(BaseCommand):

    help = 'What does this do? '

    def handle(self, *args, **options):
        for user in usuarios:
            profiles = Perfil.objects.filter(user=user)
            create_task = Task.objects.create(user=user)

On a side note, you should be more explicit about your import and not use from perfil.models import *.

From that, you can execute the command based on the file you saved it in. If you saved the file in yourapp/management/commands/dofunstuff.py than you could execute it via python manage.py dofunstuff.

👤Chris

Leave a comment