Hi,

  I'm coming to django from grails, in which which I used an in-memory
hsql database for development and in my startup script I initialized
the in-memory database with some stub values/users that were inserted
everytime I started the server. This setup was really helpful in early
stage development, where the database changes a lot(without requiring
me to update the database schema), and I'm trying to achieve similar
results with django/sqlite in memory databases.
  I placed some startup code in a middleware as follows :

from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
from django.core.management import call_command
from books.models import *
from django.contrib.auth.models import User

class StartupMiddleware(object):

        def create_publishers(self):
                p1 = Publisher(name='Apress', address='2855 Telegraph Avenue',
                        city='Berkeley', state_province='CA', country='U.S.A.',
                        website='http://www.apress.com/')
                p1.save()
                p2 = Publisher(name="O'Reilly", address='10 Fawcett St.',
                        city='Cambridge', state_province='MA', country='U.S.A.',
                        website='http://www.oreilly.com/')
                p2.save()

        def create_users(self):
                u1 = User(username='thiago', email='[email protected]')
                u1.set_password('somepass')
                u1.save()

        def create_stubs(self):
                self.create_publishers()
                self.create_users()

        def __init__(self):
                if settings.DATABASE_NAME == ':memory:':
                        call_command('syncdb', interactive=False)
                        self.create_stubs()
                raise MiddlewareNotUsed('Startup complete')


  This is not working(At least I can't logon to the admin site with
that user). I'm unsure if middleware is the best place to place
startup code, or If I'm going the right way. Any help is appreciated.

  Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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.

Reply via email to