Django ORM and phpMyAdmin

40 views
Skip to first unread message

Seth Kaïne

unread,
Nov 24, 2008, 10:08:01 AM11/24/08
to Django users
I want to have some more, please.
When I do that:

>>> python manage.py shell

>>> from httpbackend.models import Unit
>>> Unit.objects.all()
[<Unit: Toto (g.com)>, <Unit: Pingo (s.com)>, <Unit: Titi (p.com)>,
<Unit: Jason (f.com)>]
>>> u3 = Unit.objects.filter(id=3)[0]
>>> u3.status
<UnitStatus: OFFLINE>
------- I change the status for an ONLINE statement with phpmyadmin in
my Table Unit to test if django orm takes modifications to the objet
from the DB ------
>>> u3.status
<UnitStatus: OFFLINE>
------- no, nothing -------

I want to know why?

And I want to solve this, please!
thank you, come again!

Steve Holden

unread,
Nov 24, 2008, 10:33:46 AM11/24/08
to django...@googlegroups.com

At the very least you would need to read the database again, as there is
nothing that would "magically" make the already-in-memory u3 object
update itself when the database content changes.

regards
Steve

Travis Veazey

unread,
Nov 24, 2008, 12:04:38 PM11/24/08
to django...@googlegroups.com
Seth,

The reason that you don't see the values in u3 change when you change the database is that the models don't read from the database every time you want to get a value - that would be silly and would cause Django to be among the worst-performing frameworks in existence. Database reads take time, and to avoid that overhead any good ORM will get the values once and then hold them in memory.

If you were to modify your database values and then retrieve a new object (via the filter() method or whatever), you will see your modifications show up.

I'm afraid I'm too new to Django to tell you if there's a method to force a model to refresh its data from the database, but I'm an old hand at ORMs in general and I know from working with a very poorly-implemented one (this one would make a separate database call for each field value you wanted to retrieve; displaying an employee's first, middle, and last names, for example, would require 3 database queries) that reducing your round-trips to the database significantly reduces the amount of time required to process your script (in the example I mentioned, modifying the ORM to make only a single call to get all the values resulted in reducing page load time by almost a full third!).

Hope this gives you some insight.

-Travis

On Mon, Nov 24, 2008 at 6:33 AM, Steve Holden <hold...@gmail.com> wrote:

shi shaozhong

unread,
Nov 24, 2008, 3:01:14 PM11/24/08
to django...@googlegroups.com
What I have now is a data processing Python script, which runs 2 to 3
minutes. What I need now is to have a script to fire off the
execution of the script, monitor its progress and return an innerHTML
when it finished its work.

I tried to use feedback.py to call it as a subprocess. However, it
did not work at all.

I am in need of Ajax or Django script to test out the above.

Your advice and assistance will be deeply appreciated.

Regards.

David


2008/11/24 Seth Kaïne <steve....@gmail.com>:

Seth Kaïne

unread,
Nov 26, 2008, 4:32:58 AM11/26/08
to Django users
I'm learning about ORM, but it's not easy to understand the whole
picture.
I'm trying to create a "function" or a "filter" linked to my models.py
or to PHPmyAdmin to give me a signal when something is changing.
I'm making reseachs on signal on django, perhaps a solution to
explore.

If you have other informations about ORM or a way to bind the whole
thing together.

Thanks for your response.

Seth

On Nov 24, 6:04 pm, "Travis Veazey" <travis.vea...@uberforge.com>
wrote:
> Seth,
> The reason that you don't see the values in u3 change when you change the
> database is that the models don't read from the database every time you want
> to get a value - that would be silly and would cause Django to be among the
> worst-performing frameworks in existence. Database reads take time, and to
> avoid that overhead any good ORM will get the values once and then hold them
> in memory.
>
> If you were to modify your database values and then retrieve a new object
> (via the filter() method or whatever), you will see your modifications show
> up.
>
> I'm afraid I'm too new to Django to tell you if there's a method to force a
> model to refresh its data from the database, but I'm an old hand at ORMs in
> general and I know from working with a very poorly-implemented one (this one
> would make a separate database call for each field value you wanted to
> retrieve; displaying an employee's first, middle, and last names, for
> example, would require 3 database queries) that reducing your round-trips to
> the database significantly reduces the amount of time required to process
> your script (in the example I mentioned, modifying the ORM to make only a
> single call to get all the values resulted in reducing page load time by
> almost a full third!).
>
> Hope this gives you some insight.
>
> -Travis
>

Adi Jörg Sieker

unread,
Nov 26, 2008, 2:45:17 PM11/26/08
to django...@googlegroups.com
Hi,

On 26.11.2008 10:32 Uhr, Seth Kaïne wrote:
> I'm learning about ORM, but it's not easy to understand the whole
> picture.
> I'm trying to create a "function" or a "filter" linked to my models.py
> or to PHPmyAdmin to give me a signal when something is changing.
> I'm making reseachs on signal on django, perhaps a solution to
> explore.
>
>

If you change data using PHPMyAdmin the Django ORM will never notice the
change and I don't see a way of having PHPMyAdmin notify Django of a
change. Also I don't see a need for that. If you change a database
record in PHPMyAdmin. The next time someone loads a Django view the ORM
will automatically fetch the record from the database and retrieves the
new data.

Signals are, for example, used when the Django ORM changes something in
the database. A signal can then notify a django specific listener
(method). It can't tell PHPMyAdmin that something has changed.

> If you have other informations about ORM or a way to bind the whole
> thing together.
>

You won't be able to bind PHPMyAdmin with the Django ORM, the two things
have nothing to do with one another.

adi

--

Adi J. Sieker mobile: +49 - 178 - 88 5 88 13
Freelance developer web: http://www.sieker.info/profile
SAP-Developer

Reply all
Reply to author
Forward
0 new messages