Ok I managed to get that working, when I start the server I get :

Django version 1.1.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table books_publisher
Creating table books_author
Creating table books_book

the only problem is that when I make the first request it blocks for
console input with the following message :

You just installed Django's auth system, which means you don't have
any superusers defined.
Would you like to create one now? (yes/no)

If I create a user with the same name created in the startup
middleware I get unique constraint database violation, if I choose no
everything proceeds smoothly and I can log on with my stub user. I
don't want the first request blocking everytime to ask for a new user,
can I remove that prompt?

 Thanks.

On Mon, Aug 16, 2010 at 11:57 PM, Thiago de Arruda <tpadilh...@gmail.com> wrote:
>  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='thi...@pass.com')
>                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 django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to