Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8144 > unrolled thread

Using django ORM from web browser and from command line apps

Started byNews123 <news1234@free.fr>
First post2011-06-22 01:39 +0200
Last post2011-06-22 03:57 -0700
Articles 6 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Using django ORM from web browser and from command line apps News123 <news1234@free.fr> - 2011-06-22 01:39 +0200
    Re: Using django ORM from web browser and from command line apps Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-21 18:09 -0600
      Re: Using django ORM from web browser and from command line apps News123 <news1234@free.fr> - 2011-06-22 02:21 +0200
        Re: Using django ORM from web browser and from command line apps Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-21 19:08 -0600
          Re: Using django ORM from web browser and from command line apps News123 <news1234@free.fr> - 2011-06-22 03:18 +0200
        Re: Using django ORM from web browser and from command line apps "bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com> - 2011-06-22 03:57 -0700

#8144 — Using django ORM from web browser and from command line apps

FromNews123 <news1234@free.fr>
Date2011-06-22 01:39 +0200
SubjectUsing django ORM from web browser and from command line apps
Message-ID<4e012bc4$0$1555$426a74cc@news.free.fr>
Hi,

I'm having a django browser application.

There's certain administrative tasks, that I'd like to perform from the
command line (cronjob or manually).
As these scripts might be huge and might consume quite some memory I'd
prefer, that they were not part of the normal application and would just
consume memory during the administrative phase.

I am not sure, whether this is a use case really being intended.

I wanted to know whether there are any precautions to take if I do this.

The one issue, that I could imagine is that Django (if I understood
correctly) performs normally database transaction based an a http request.

What would happen if I don't do anythong special in a script.
Would the entire runtime of the script be considered a transaction?

Are there any special commands that I have to use in order to indicate
when a transaction starts / stops?


Thanks in advance for suggestions.

Please look also at  a related question.

[toc] | [next] | [standalone]


#8150

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-06-21 18:09 -0600
Message-ID<mailman.257.1308701430.1164.python-list@python.org>
In reply to#8144
On Tue, Jun 21, 2011 at 5:39 PM, News123 <news1234@free.fr> wrote:
> Hi,
>
> I'm having a django browser application.
>
> There's certain administrative tasks, that I'd like to perform from the
> command line (cronjob or manually).
> As these scripts might be huge and might consume quite some memory I'd
> prefer, that they were not part of the normal application and would just
> consume memory during the administrative phase.
>
> I am not sure, whether this is a use case really being intended.

It sounds like you probably want a custom management command:

https://docs.djangoproject.com/en/1.3/howto/custom-management-commands/

> I wanted to know whether there are any precautions to take if I do this.
>
> The one issue, that I could imagine is that Django (if I understood
> correctly) performs normally database transaction based an a http request.

If you have the TransactionMiddleware enabled, yes.  Otherwise the
default is to commit everything immediately.

> What would happen if I don't do anythong special in a script.
> Would the entire runtime of the script be considered a transaction?

The default here is also to commit everything immediately.  Since
there is no HTTP request, the TransactionMiddleware does not get
invoked even if enabled.  For controlled transactions you will need to
use the commit_on_success or commit_manually decorator /
context-managers:

https://docs.djangoproject.com/en/1.3/topics/db/transactions/

Cheers,
Ian

[toc] | [prev] | [next] | [standalone]


#8151

FromNews123 <news1234@free.fr>
Date2011-06-22 02:21 +0200
Message-ID<4e0135a2$0$4132$426a74cc@news.free.fr>
In reply to#8150
Hi Ian,

On 06/22/2011 02:09 AM, Ian Kelly wrote:
> On Tue, Jun 21, 2011 at 5:39 PM, News123 <news1234@free.fr> wrote:
>> I'm having a django browser application.
>>
>> There's certain administrative tasks, that I'd like to perform from the
>> command line (cronjob or manually).

> It sounds like you probably want a custom management command:
> 
> https://docs.djangoproject.com/en/1.3/howto/custom-management-commands/
Didn't know this existed.
Yes this is definitely a way to go. At least for part of the commands,
that I plan to implement.
Out of curiousity: Do you know whether the imports would be executed for
each potential command as soon as I call manage.py or only
'on demand'?

> 
>> I wanted to know whether there are any precautions to take if I do this.
>>
>> The one issue, that I could imagine is that Django (if I understood
>> correctly) performs normally database transaction based an a http request.
> 
> If you have the TransactionMiddleware enabled, yes.  Otherwise the
> default is to commit everything immediately.

Good to know.
> 
>> What would happen if I don't do anythong special in a script.
>> Would the entire runtime of the script be considered a transaction?
> 
> The default here is also to commit everything immediately.  Since
> there is no HTTP request, the TransactionMiddleware does not get
> invoked even if enabled.  For controlled transactions you will need to
> use the commit_on_success or commit_manually decorator /
> context-managers:
> 
> https://docs.djangoproject.com/en/1.3/topics/db/transactions/
> 
Thanks this url is very clear. :-)

I will use the commit model as required for my different tasks

[toc] | [prev] | [next] | [standalone]


#8157

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-06-21 19:08 -0600
Message-ID<mailman.260.1308704957.1164.python-list@python.org>
In reply to#8151
On Tue, Jun 21, 2011 at 6:21 PM, News123 <news1234@free.fr> wrote:
> Out of curiousity: Do you know whether the imports would be executed for
> each potential command as soon as I call manage.py or only
> 'on demand'?

Off the top of my head, I don't know.

[toc] | [prev] | [next] | [standalone]


#8161

FromNews123 <news1234@free.fr>
Date2011-06-22 03:18 +0200
Message-ID<4e0142fa$0$4138$426a74cc@news.free.fr>
In reply to#8157
On 06/22/2011 03:08 AM, Ian Kelly wrote:
> On Tue, Jun 21, 2011 at 6:21 PM, News123 <news1234@free.fr> wrote:
>> Out of curiousity: Do you know whether the imports would be executed for
>> each potential command as soon as I call manage.py or only
>> 'on demand'?
> 
> Off the top of my head, I don't know.

Never mind.
WIill jsut add a print statement when I make my first test.
This should clearly show whether the module is imported all the time or
only on demand.

[toc] | [prev] | [next] | [standalone]


#8196

From"bruno.desthuilliers@gmail.com" <bruno.desthuilliers@gmail.com>
Date2011-06-22 03:57 -0700
Message-ID<5534189f-6105-4336-9a28-0b6d71cb438b@m9g2000yqe.googlegroups.com>
In reply to#8151
On Jun 22, 2:21 am, News123 <news1...@free.fr> wrote:
> Out of curiousity: Do you know whether the imports would be executed for
> each potential command as soon as I call manage.py or only
> 'on demand'?

Why would you care ? Just importing the module shouldn't have any side
effect.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web