djangocrondjango-custom-manager

Cron job for Django File


I want to setup a Cron job to run a django file.

What I want to know is django-cron a good option for this? i.e. or are there any other apps that can be used? If no, how to run a django file through command line ?

admin@ADMIN-PC ~/workspace/bolt (master)
$ python ./log/cron.py
Traceback (most recent call last):
  File "./log/cron.py", line 3, in <module>
    from account.models import UserProfile
ImportError: No module named account.models

I have set the following variable

admin@ADMIN-PC ~/workspace/bolt (master)
$ export DJANGO_SETTINGS_MODULE=settings

I keep getting these errors as the files that are being referenced have direct imports

from foo.models import * 

Any help will be highly appreciated.

Custom Command

from django.core.management.base import BaseCommand, CommandError
import pdb
import datetime

from too.models import UserProfile
from foo.api import end_all_foo_conversations


class Command(BaseCommand):
    # in minutes
    def handle(self,*args,**options):
        print datetime

The error I am getting while trying to run the command is as follows:-

'queryset': self.rel.to._default_manager.using(db).complex_fi

imit_choices_to), AttributeError: 'str' object has no attribute '_default_manager'


Solution

  • I think you should write a custom management command and run it through manage.py.