Because i can't find related post here, so i post this example. maybe someone else need.
Some times, you just want to use the useful models of django without thinking any sql statement. Maybe you want to run a script to know which user's birthday in your database is today, this little job should not run in the view.py. It should run in the cron table of linux os every day, so that your users can receive birthday card from your system. this example is so easy, all you know is loading the settings.py correctly. Your script must place in your project's directory. script example: #!/usr/bin/env python # -*- coding: utf8 -*- import settings from django.core.management import setup_environ setup_environ(settings) # before do something else, # the three lines above here is your first operation. from django.db.models import get_model from datetime import date if __name__ == '__main__': ----# the 'tmp' is your project's name, ----# and this script must place in the 'tmp' directory. ----# the 'person' is your model's name. ----Person = get_model('tmp', 'person') ----# when you get the model, ----# you can use it just like you use it in the view.py ----P = Person(name='hoamon', birth=date(1977, 10, 18)) ----P.save() ----for p in Person.objects.all(): --------if p.birth == date(1977, 10, 18): ------------print p.name ----for p in Person.objects.filter(birth=date(1977, 10, 18)): --------print p.name now you can put /somepath/tmp/birthday.py in the cron table. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---