Wednesday, March 11, 2015

Re: Accessing Django models using DJANGO_SETTINGS_MODULE

On Sun, Mar 8, 2015 at 5:21 AM, Dheerendra Rathor
<dheeru.rathor14@gmail.com> wrote:
> I've a django project and I've few models like ChatRoom and Chat etc
>
> I'm accessing the ChatRooms from commandline using ipython as follow
> In [1]: import os
>
> In [2]: os.environ['DJANGO_SETTINGS_MODULE'] = 'chat_project.settings'
>
> In [3]: from chat.models import Chat, ChatRoom
>
> In [4]: ChatRoom.objects.all()
> Out[4]: [<ChatRoom: Lab 01>, <ChatRoom: Lab 02>, <ChatRoom: Lab 03>,
> <ChatRoom: Lab 04>, <ChatRoom: Lab 05>, <ChatRoom: Lab 06>, <ChatRoom: Lab
> 07>, <ChatRoom: Lab 10>, <ChatRoom: Lab 13>, <ChatRoom: Lab 14>, <ChatRoom:
> Lab 15>, <ChatRoom: Lab 16>]
>
> Now, I'm adding more ChatRooms through web interface - Lab 17, Lab 18 and
> deleting Lab 10
> Now the new output of
> In [5]: ChatRoom.objects.all()
>
> The output is still the same
> Out[5]: [<ChatRoom: Lab 01>, <ChatRoom: Lab 02>, <ChatRoom: Lab 03>,
> <ChatRoom: Lab 04>, <ChatRoom: Lab 05>, <ChatRoom: Lab 06>, <ChatRoom: Lab
> 07>, <ChatRoom: Lab 10>, <ChatRoom: Lab 13>, <ChatRoom: Lab 14>, <ChatRoom:
> Lab 15>, <ChatRoom: Lab 16>]
>
> the webinterface is running as wsgi application on gunicorn server.
>
> I think the output on command line is not changed because the django default
> model manager is accessing the objects from cache and not from database
> itself.

I don't think that is likely. What version of django do you use, what
database engine do you use, what options have you configured it to
use? Django version matters a lot in this case.

It sounds like the shell is running within a transaction, so that
reads are repeatable within it - doing the same query will always
return the same results. This is the purpose of transactions, nothing
changes in the database until you commit your transaction.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1J69PUs6FsGKuNL9aJ%3DNDmLW4XY6vmMTjBFHxpOtQXEQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment