0

I would like to create a simple dynamic Sudoku game. Idea is to create new "puzzle" every hour then put it to database and let users solve it. Each solve attempt is compared with database for verification. For that purpose I would like to create python script that generates puzzle and puts it to the database. My database set in models looks like this:

from django.db import models

class user(models.Model):
    name = models.CharField(max_length=30)
    password = models.CharField(max_length=30)
    time_registered=models.DateTimeField()
    time_uploaded=models.DateTimeField()
    points=models.IntegerField()
    saved_sudoku=models.CommaSeparatedIntegerField(max_length=81)
    solved=models.BooleanField()

    def __str__(self):
        return self.name

class server_sudoku(models.Model):
    time_uploaded=models.DateTimeField()
    generated_sudoku=models.CommaSeparatedIntegerField(max_length=81)

Now, when I use :

name1=request.POST["name"]
pass1=request.POST["password"]
newuser=user(name=name1,password=pass1,time_registered=datetime.datetime.now(),time_uploaded=datetime.datetime.now(),points=0,saved_sudoku="",solved=False)
newuser.save()

in views.py it creates new user. So to verify my idea I created application "generate_sudoku.py". To test its connection to database I just try to add user. Code looks as follows:

#!/usr/bin/env python
from db_interface.models import user

import random
import datetime

newuser=user(name="name", password="pass", time_registered=datetime.datetime.now() ,time_uploaded=datetime.datetime.now(), points=0, saved_sudoku="", solved=False)
newuser.save()

This simple app gives me this error:

raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Hope I made it clear, I would like to run this application by windows scheduler so that it is automatically run every hour...

2 Answers 2

3

Use a custom manage.py command.

Sign up to request clarification or add additional context in comments.

Comments

0

First link on google : http://eliasbland.wordpress.com/2010/01/25/importerror-settings-cannot-be-imported-because-environment-variable-django_settings_module-is-undefined/ ;)

This works for me (in a lambda script, not _ _init _ _.py file) :

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from django.contrib.auth.models import User #import django stuff after
print User.objects.all()

3 Comments

I added an example, try it :)
same old error, I feel like Daniels reply is the right way to go but I still struggle to get it working as described in my post ...
I have to admit, Daniel's way to do is probably the right one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.