Django an STI

2009-03-06 Thread Vbabiy

I know django does not support STI, but I was wondering if there is
any way I can implement this behaviour.

Here is an example of what I would like:

class Tracker(models.Model):
   notifications = models.ForeignKey(Notification)

class Notification(models.Model):
# Common fields
pass

class EmailNotification(Notification):
   pass

class SmsNotification(Notification):
   pass


# I would be able to iterate over all types of notification
for n in tracker.notifications:
   print n
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django and Python Warnings

2009-03-06 Thread Graham Dumpleton



On Mar 7, 12:50 pm, Malcolm Tredinnick 
wrote:
> On Fri, 2009-03-06 at 18:12 -0500, Jacob Kaplan-Moss wrote:
> > On Fri, Mar 6, 2009 at 5:56 PM, Graham Dumpleton
> >  wrote:
> > > Anyway, the issue is that at the moment mod_wsgi doesn't have an
> > > equivalent for the command line -W option. Do people feel it would be
> > > useful to have a directive in mod_wsgi which allows one to control the
> > > warnings mechanism, ie., does the same as -W?
>
> > It's probably useful. Frankly, though, I'm only using mod_wsgi for
> > production, not development, and I'd never let code spewing warnings
> > make its way into production. So doesn't help/hurt me personally, but
> > it's probably useful for less strict development environments.
>
> I think it would be worthwhile if not too painful to add, Graham.

BTW, if there is anything else you would like to see in mod_wsgi, now
is the time to speak up as am close to point where can wrap up work on
mod_wsgi 3.0.

I am still toying with whether I add a few things or not. The first of
these is optionally enabled support in daemon mode for X-Sendfile
header where sending of file is actually performed back in main Apache
worker process. Not sure though whether I want to do this or not as it
raises various permissions issues as reading/sending of file not done
as same user as daemon but Apache user.  Also, have already added
support to daemon mode for CGI style Location header redirect when
status is 200. This is like X-Accel-Redirect in nginx in that the URL
goes back through Apache request matching and so governed by Apache
permissions module and target of internal redirect can be dynamic
application as well as static. As such, have preference for just that
at the moment, but might be convinced otherwise. This all may be
relevant as I noted some discussion on a Django ticket in relation to
wsgi.file_wrapper about having X-Sendfile support as well or instead
of it.

The second thing am thinking about is some sort of automatic support
for fixing up WSGI request environment when Apache/mod_wsgi put behind
a proxy and so need to deal with X-Forwarded-Host, X-Forwarded-For and
X-Forwarded-Proto. I know some frameworks have some support for this,
but not sure if Django does. What one normally has to do with WSGI is
add a top level middleware which does the fixup, but thinking ahead
for commodity hosting mechanism interested in way that hoster could
automatically set it up and user not have to worry about it. Feedback
on whether Django does anything with these headers would be helpful.

If interested to know what is coming in mod_wsgi 3.0 have a look at:

  http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300

I probably should blog about mod_wsgi 3.0 and reference this as a way
of getting feedback. :-)

Graham

> I like the recent post you did on Django development under mod_wsgi and
> want to encourage people to use that more frequently Being able to see
> warnings the framework will raise in development is pretty important
> (otherwise, they'd be errors, not warnings), so that will help there.
>
> By the way, for those not following what Graham's written, (a) shame on
> you! and (b) see
>
> http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django...
>
> and
>
> http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-o...
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: append_slash and mod_wsgi problem when Django lives in subdirectory

2009-03-06 Thread Benedykt

On Mar 5, 11:51 pm, Graham Dumpleton 
wrote:

> What version of Django are you using?
>
> Are you perhaps using a pre 1.0 version where SCRIPT_NAME, which
> defines mount point, was not being properly handled by Django.

Yes, it was the reason - I was using 0.9.7. I upgraded to the current
version and now it works ok.

Thanks a lot!


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



Re: Is a Complex filter with __in and __exact possible?

2009-03-06 Thread Malcolm Tredinnick

One day I'll stop posting in this thread. Really.

On Sat, 2009-03-07 at 12:03 +1100, Malcolm Tredinnick wrote:

> However, find things that are simultaneously in all those categories can
> be done without all the annotation nonsense I posted. Simply
> 
> 
> Publication.objects.filter(article=1).filter(article=2).filter(article=3)
> 
> It's a short loop to build up such a set dynamically. The difference
> between that (3 filter calls) and you Q-object version is described in
> the documentation:
> http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships

I forgot to mention that this approach is probably only practical for a
small number of article instances. Each filter() adds a new table join,
so at some point the database will complain. Either literally, about too
many joins, or by taking ages to attempt to optimise and execute the
query.

For a large number of article instances, the annotation-based solution I
gave earlier is more appropriate.

Regards,
Malcolm


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



multiple S3 buckets using David Larlet's S3Storage.py

2009-03-06 Thread wynfred

David Larlet's Amazon S3 wrapper for Django seems widely used, and I'm
inclined to use it. However, there's something in the documentation
that confuses me:
http://code.welldev.org/django-storages/wiki/S3Storage

It seems as though one can only use a single bucket, in
AWS_STORAGE_BUCKET_NAME in settings.py, rather than specifying a
bucket in a FileField or ImageField field definition in models.py.

Our application needs to use distinct S3 buckets for different files
(images, feeds, etc.). Looking at the S3Storage.py code:
http://code.welldev.org/django-storages/src/af5d6b4c2d07/S3Storage.py

it seems like it might be possible to specify different S3 buckets for
different fields, but I'm not entirely clear on how one might do that.

Any suggestions to help point me in the right direction?

Thanks in advance for the excellent support here.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: manage.py dumpdata app.model doesn't seem to work?

2009-03-06 Thread Russell Keith-Magee

On Sat, Mar 7, 2009 at 5:48 AM, Alex Koshelev  wrote:
> This `dumpdata` command you can only serialize whole application not just
> its models.

This isn't completely correct. As of [9921], you can specify
individual models to dumpdata. However, [9921] was committed after the
v1.1 alpha 1 release, so you'll need to be using a recent trunk
checkout to access this feature.

Yours,
Russ Magee %-)

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



Re: pythonpath on Ubuntu 8.10

2009-03-06 Thread Ishwor Gurung
Hi

python_fan wrote:
> Hey,
> 
> I have an application that I'm running using Django's built-in server
> on both Windows XP and Ubuntu 8.10. While it is wokring perfectly fine
> on XP, I get import errors in Ubuntu. When I tried printing pythonpath
> on Ubuntu, I managed to locate the problem. It seems like if I start
> the server with a python script it happens before the shell is updated
> with correct pythonpath path from the .bashrc. However, if i do it
> manually it starts perfectly fine (since it manages to update
> pythonpath at the start).
> 
> So, the question is: Is it possible to do anything to make it to work
> with automatic start-up? I.e. update Django's pythonpath somehow? Or
> maybe put environment variables somewhere else than .bashrc? Anyone?


I haven't read your next mail but basically if I understood your
quesiton correctly, you are planning to deploy apps on the django's
devel server, you can export those variables in a system-wide
/etc/bash.bashrc.But, a reminder here, django's devel server
automatically exports those for you so you need not do it. However, if
you plan to run using "django-admin.py", you'd obviously need
PYTHONPATH and DJANGO_SETTINGS_MODULE set accordingly.

i...@debian:[~] echo $PYTHONPATH
/home/hutch/apps/wikinotes
i...@debian:[~] echo $DJANGO_SETTINGS_MODULE
settings
i...@debian:[~] django-admin.py runserver
Validating models...
0 errors found

Django version 1.0.2 final, using settings 'settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Hope that helps. The django documentation has all these info if you'd
want to read.

Cheers,
Ishwor


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Compressed fixtures?

2009-03-06 Thread Alex Gaynor

This only works on the latest development version of Django, not 1.0.

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: Django Resource Usage

2009-03-06 Thread Alex Gaynor

Also consider a hosting mechanism not yet mentioned in the docs, mod_wsgi.

Alex

On 3/6/09, Graham Dumpleton  wrote:
>
>
>
> On Mar 6, 10:45 pm, Paulo  wrote:
>> Well, this leads me to an unknown path. Where i can find more
>> information about how to install it and tweak it?
>
> You still aren't saying how you intend to host it.
>
> If you do not know, start by looking at the deployment mechanisms
> supported by Django as explained in Django documentation.
>
> Graham
>
>> On 6 mar, 00:04, Graham Dumpleton  wrote:
>>
>> > On Mar 6, 1:24 pm, Malcolm Tredinnick 
>> > wrote:
>>
>> > > On Thu, 2009-03-05 at 18:08 -0800, Paulo wrote:
>> > > > Hi
>>
>> > > > I want to install Django on my webserver, but i would like to know
>> > > > from you if django has an intense resource usage (memory, cpu) or
>> > > > it's
>> > > > not a concern?
>>
>> > > As always, it depends on what you're doing. There simply *cannot* be
>> > > any
>> > > general answer to that question. That being said, typing "resource
>> > > usage" into the search box on the django-users Google Groups page
>> > > turns
>> > > up a bunch of previous messages on this topic. Searching the archives
>> > > will certainly give you some ideas of things to consider when
>> > > benchmarking.
>>
>> > > The solution is always to profile and benchmark on your development
>> > > systems before deploying.
>>
>> > It also depends on how you intend to deploy Django. If you try and run
>> > it under mod_python or mod_wsgi embedded mode in Apache with prefork
>> > MPM, then it can take huge amounts of memory. Even with worker MPM you
>> > have to be careful and consider changing the default Apache MPM
>> > settings as they default to be values more appropriate for static file
>> > serving and PHP. Better deployment scenarios are mod_wsgi daemon mode
>> > or fastcgi solutions with number of processes/threads used strictly
>> > controlled.
>>
>> > So, how do you intend deploying it?
>>
>> > Graham
> >
>


-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Re: translating app name ... again

2009-03-06 Thread Malcolm Tredinnick

On Sat, 2009-03-07 at 12:21 +1100, Malcolm Tredinnick wrote:
[...]
> All of those are bugs (the same bug: not marking app name for
> translation). If you'd like to open a ticket and drop in a patch, it's
> an more-or-less obviously correct set of changes to make.
> 
> Put it in the "internationalisation" component.

Looks like the discussion for the technical fixes here (and Ramiro
Morales seems to be taking care of the bug filing) has moved to the
django-i18n list: 

http://groups.google.com/group/Django-I18N/browse_thread/thread/bdcdaf433bfcd144

Regards,
Malcolm


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



Re: How do I model optional Parent/Child relationships, e.g. not all Tasks are related to a Project?

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 15:45 -0800, Doug wrote:
> I have 2 related models, Project and Task.
> 
> What's the best way to set up my models so a Task can either be part
> of a Project or not? Do I set up a "dummy" Project for Tasks which
> aren't related to a specific Project? Or is there a way to set "Null"
> on the FK of a Task for the Project field?

Every field in Django allows the "null" option. See

http://docs.djangoproject.com/en/dev/ref/models/fields/#null

Regards,
Malcolm



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



Re: Django and Python Warnings

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 18:12 -0500, Jacob Kaplan-Moss wrote:
> On Fri, Mar 6, 2009 at 5:56 PM, Graham Dumpleton
>  wrote:
> > Anyway, the issue is that at the moment mod_wsgi doesn't have an
> > equivalent for the command line -W option. Do people feel it would be
> > useful to have a directive in mod_wsgi which allows one to control the
> > warnings mechanism, ie., does the same as -W?
> 
> It's probably useful. Frankly, though, I'm only using mod_wsgi for
> production, not development, and I'd never let code spewing warnings
> make its way into production. So doesn't help/hurt me personally, but
> it's probably useful for less strict development environments.

I think it would be worthwhile if not too painful to add, Graham.

I like the recent post you did on Django development under mod_wsgi and
want to encourage people to use that more frequently Being able to see
warnings the framework will raise in development is pretty important
(otherwise, they'd be errors, not warnings), so that will help there.

By the way, for those not following what Graham's written, (a) shame on
you! and (b) see

http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html

and

http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-on.html

Regards,
Malcolm



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



[OT] python + rrdtool?

2009-03-06 Thread Jeremy Dunck

Does anyone use a python interface to rrdtool?  I've looked around,
and it seems there are several interfaces, but non have been updated
recently.

If someone could report success with one, I'd appreciate it.

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



Re: pythonpath on Ubuntu 8.10

2009-03-06 Thread python_fan

Seems like I found one solution to that: Add --
pythonpath="path_to_your_app" to the manage.py runserver call. Any
better solutions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: count and group by aggregation

2009-03-06 Thread kbs

thanks
that worked

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



Re: forms.ModelForm

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 12:25 -0800, mike171562 wrote:
> I am using Django's ModelForm in a template im working on. I am trying
> to use it to display the Django User Object and an extension I added
> of the user model, what would be the correct way to display my User
> model extension in my template, I would like to be able to edit the
> User information and the account number I have added all from the same
> form. Thanks.

A Django Form object represents only a part of an HTML form (which is
why need to write the HTML "form" tag in the template, for example). You
can pass multiple form objects through from your view function to the
template and render both of them inside the same HTML form.

If you want to intermingle fields, you can define extra form fields on a
model form. For example:

class MyForm(forms.ModelForm):
extra = forms.CharField(max_length=50)

class Meta:
model = models.Tag


That will put the extra fields at the end of the model form.

If you want to put the extra fields in the middle of the model fields
somehow, you can either write a custom __init__ method to tweak the
field ordering (you'll have to read the forms code a bit to see what
needs tweaking). Alternatively, you can take the not unreasonable
approach that you've gone beyond the scope of modelforms by this point
and just write a normal Form class that contains the fields.

I've always been an interested observer of people trying to make
automatic model-related forms do all sorts of funky things, because I
hardly ever use them. So many of my use-cases don't have forms mapping
directly to models, so I write a normal Form class and then my view
knows how to take fields from the Form instance and convert that data to
the appropriate models. At some point, it's a fairly grief-free way to
handle anything beyond the straight model -> form -> model conversion.
But, as you can see from the above, you aren't short of options here.

Regards,
Malcolm


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



Re: template include and for loop speed

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 10:51 -0500, Jacob Kaplan-Moss wrote:
> On Fri, Mar 6, 2009 at 4:25 AM, Thierry  wrote:
> > Why is an include tag so much heavier on the template system?
> 
> Because it has to search for the given template on the file system.
> Depending on how you've got TEMPLATE_LOADERS and TEMPLATE_DIRS set,
> this could search in dozens of places.

And the "rating_small" variable in the original poster's case shows why
we have to reload the included template each time: it could be a
different one on different loops.

There are some optimisation possibilities here (e.g. if it's loaded from
a string literal), but we need to put in a rendering-reset feature to
the template code -- which we need to fix a couple of existing bugs
anyway, so it's probably coming soon -- first. That's something somebody
might want to look at in the Django 1.2 timeframe as a little
side-project.

Regards,
Malcolm



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



Re: translating app name ... again

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 07:01 -0800, patrickk wrote:
> so, now here´s a little tutorial for translating app-names throughout
> the admin-interface:

Nice summary. :-)

> 3. change app-names in index.html /// on line 18 replace {% blocktrans
> with app.name as name %}{{ name }}{% endblocktrans %} with {% trans
> app.name %}

Not sure what's going on there, but it's a bug. Blocktrans shouldn't be
behaving strangely (using "trans" isn't wrong and we could just switch
to that, but I'd like to understand what's going with "blocktrans",
too).

That's why I thought this should have just worked with marking the names
for translation in a file somewhere. Hmm ... mysterious. :-(
 
> 
> 4. change breadcrumbs in change_list.html /// on line 25 replace
> {{ app_label|capfirst }} with {% trans app_label %}
> 
> 5. change breadcrumbs in change_form.html /// on line 28 replace
> { app_label|capfirst }} with {% trans app_label %}
> 
> 6. change app-names in app_index.html /// on line 11 replace {%
> blocktrans with app.name as name %}{{ name }}{% endblocktrans %} with
> {% trans app.name %}
> 
> 7. change title in base_site.html /// on line 69 replace {{ title }}
> with {% trans title %}

All of those are bugs (the same bug: not marking app name for
translation). If you'd like to open a ticket and drop in a patch, it's
an more-or-less obviously correct set of changes to make.

Put it in the "internationalisation" component.

Regards,
Malcolm



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



pythonpath on Ubuntu 8.10

2009-03-06 Thread python_fan

Hey,

I have an application that I'm running using Django's built-in server
on both Windows XP and Ubuntu 8.10. While it is wokring perfectly fine
on XP, I get import errors in Ubuntu. When I tried printing pythonpath
on Ubuntu, I managed to locate the problem. It seems like if I start
the server with a python script it happens before the shell is updated
with correct pythonpath path from the .bashrc. However, if i do it
manually it starts perfectly fine (since it manages to update
pythonpath at the start).

So, the question is: Is it possible to do anything to make it to work
with automatic start-up? I.e. update Django's pythonpath somehow? Or
maybe put environment variables somewhere else than .bashrc? Anyone?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Figuring out what has changed at save()

2009-03-06 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 22:02 -0800, hanks...@gmail.com wrote:
> Sorry for the unwieldy title, but nothing else strikes me at the
> moment.
> 
> I have a blog app -- a version of basic.blog, actually. There's a
> field in the model called "status" with two options: "draft" and
> "public."
> 
> What I want to do is trigger an action the first time (and /only/ the
> first time) a particular instance is saved as "public."
> 
> So:
> 
> Write a post in the admin, save as draft --> No action
> Edit the post some, save as draft again --> No action
> Edit more, publish   --> Action triggered!
> Edit again   --> No action.
> 
> How would I go about this? My thought is to override save(), but I
> can't figure out how to inspect the instance at that point to
> determine if the status attribute has changed since it was created.

If the object has a primary key value, assuming you don't set that
manually yourself, then it already exists in the database. So fetch the
existing values.

def save(*args, **kwargs):
   if self.pk:
  old_version = self.model.objects.get(pk=self.pk)
  # Work out the changes between "self" and "old_version"

(Before anybody starts complaining about the extra database hit, think
about how relatively infrequently new posts are saved in the scheme of
things. Even if it was at the rapid rate of once per minute, you
wouldn't notice the extra read.)

>  I
> assume that this information must be in there somewhere, since it
> seems like you'd need it to generate the SQL statement.

No. Django just checks to see if the record is already in the database.
We can't make any assumptions based on the primary key value for all
models, since people can assign to that attribute. However, if you know
that *your* code doesn't assign to that attribute, which is a pretty
normal case, you'll be able to use the pk test to know if you're saving
or updating.

One day (maybe 1.2 timeframe?!) we'll add at least optional change
detection to models and only update changed columns. There's a couple of
implementation things to be worked out there first, but it's on the
medium-term feature list.

Regards,
Malcolm



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



Re: Cherrypy and view variables caching?

2009-03-06 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 22:42 -0800, John M wrote:
> Well, given my example, i would think it does.

I'm sorry you think that, but if it was clear to me, I wouldn't have
asked the question. At no point in your earlier posts did you show any
examples of or mention using generic views.

>   I put the generic's in
> the URL.PY file and it's not performing as planned, I'm not sure how I
> would keep the generic view inside the URL and get what I want?

A generic view in a URL Conf file is just a function reference that is
called. It sounds like the problem is some initial data that you're
wanting to set up. You need that to be executed each time if it's ever
going to change (such as the concept of "one week ago"), so it also has
to be inside a function that is called, which means not just using
generic views.

A reasonably natural way to do that if you're using a generic view and
want to pass in extra information is to write a view function which does
all the initial setup and then passes the dynamic information via the
extra_context parameter to the generic view.

Here's an old blog post I wrote on this topic which has some concrete
code samples and is still valid today:

http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/

Regards,
Malcolm



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



Re: Is a Complex filter with __in and __exact possible?

2009-03-06 Thread Malcolm Tredinnick

On Fri, 2009-03-06 at 00:11 -0800, Daniel Hepper wrote:
> > > Book.objects.filter(Q(categories=1), Q(categories=2), Q(categories=3))
> >
> > Not if you were trying to solve the original poster's question. Your
> > query is exactly the same as what he tried to do originally.
> 
> I played a bit with the query and just wanted to clarify that it is
> not exactly the same. (Note that the Q-objects are "AND"ed, not
> "OR"ed).
> 
> >>> Publication.objects.filter(article__in=[1,2,3])
> [, ,
> , ,
> ]
> 
> >>> Publication.objects.filter(Q(article=1), Q(article=2), Q(article=3))
> []
> 
> (I've used the models from the Many-To-Many-Example _1.)

Yes, you're completely correct. My apologies (and thanks for not just
believe me)! I was being lazy and didn't think it through. The second
query tries to find a single article objects that simultaneously has pk
values of 1, 2 and 3, as you notice in your SQL. Unsurprisingly, that
doesn't exist.

> 
> The second query will always return an empty result. This is the
> generated SQL:
> 
> {'sql': u'SELECT "bookstore_publication"."id",
> "bookstore_publication"."title" FROM "bookstore_publication" INNER
> JOIN "bookstore_article_publications" ON ("bookstore_publication"."id"
> = "bookstore_article_publications"."publication_id") WHERE
> ("bookstore_article_publications"."article_id" = 1  AND
> "bookstore_article_publications"."article_id" = 2  AND
> "bookstore_article_publications"."article_id" = 3 ) ORDER BY
> "bookstore_publication"."title" ASC LIMIT 21',
>  'time': '0.000'}
> 
> Thinking about it, this makes perfect sense, as the condition is on
> the article, not on the set.
> 
> It would be nice to have special lookups for Many-To-Many-Fields or
> related sets, which would allow something like
> Publication.objects.filter(article_set__exact=[1,2,3])

That can be done already. Although, as I mentioned in my first reply to
the original poster, the question is ambiguous.

I also realised last night that my first reply on this topic also had a
stupid mistake caused by me trying to answer both questions at once.
I've already shown how to get all objects that are in precisely those
categories and no others. Making that easier (e.g. two straight filters
or something similar) is actually fairly hard internally, since the API
shouldn't suck (I've spent a couple of hours thinking about it and
poking at the code, so I'm not just guessing here).

However, find things that are simultaneously in all those categories can
be done without all the annotation nonsense I posted. Simply


Publication.objects.filter(article=1).filter(article=2).filter(article=3)

It's a short loop to build up such a set dynamically. The difference
between that (3 filter calls) and you Q-object version is described in
the documentation:
http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships

Regards,
Malcolm


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



How do I model optional Parent/Child relationships, e.g. not all Tasks are related to a Project?

2009-03-06 Thread Doug

I have 2 related models, Project and Task.

What's the best way to set up my models so a Task can either be part
of a Project or not? Do I set up a "dummy" Project for Tasks which
aren't related to a specific Project? Or is there a way to set "Null"
on the FK of a Task for the Project field?

Here are my models: http://dpaste.com/8321/

Many thanks,

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



Re: Can't run django on Apache

2009-03-06 Thread xankya

One thing I noticed in my windows and sun solaris is that, there is no
trailing slash in python paths. When I added trailing slash, apache
showed error. So you might as well try removing trailing slash in
python paths.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Microsoft using Django?

2009-03-06 Thread Anderson Santos

Dãr, it was a IE bug displaying a error message from my own server.
Sorry

On 6 mar, 20:12, Anderson Santos  wrote:
> I tried to access a file from Microsoft website I got a Django error, are
> they really using Django? (It's not phising or spam, just copy and paste the
> link)
>
> http://download.microsoft.com/download/f/3/c/f3c93e70-ccdc-46c9-bbd4-...
>
> Cheers,
>
> Anderson
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django and Python Warnings

2009-03-06 Thread Jacob Kaplan-Moss

On Fri, Mar 6, 2009 at 5:56 PM, Graham Dumpleton
 wrote:
> Anyway, the issue is that at the moment mod_wsgi doesn't have an
> equivalent for the command line -W option. Do people feel it would be
> useful to have a directive in mod_wsgi which allows one to control the
> warnings mechanism, ie., does the same as -W?

It's probably useful. Frankly, though, I'm only using mod_wsgi for
production, not development, and I'd never let code spewing warnings
make its way into production. So doesn't help/hurt me personally, but
it's probably useful for less strict development environments.

Jacob

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



Microsoft using Django?

2009-03-06 Thread Anderson Santos
I tried to access a file from Microsoft website I got a Django error, are
they really using Django? (It's not phising or spam, just copy and paste the
link)

http://download.microsoft.com/download/f/3/c/f3c93e70-ccdc-46c9-bbd4-70d94bdd0cc9/IEDevToolBarSetup.msi/


Cheers,


Anderson

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



Re: Three Physical Tiers

2009-03-06 Thread Ishwor Gurung

ruffeo wrote:
> I guess my question is how do you call a remote model object on a
> different web server using Django MTV framework.

I reckon you'd have to use some sort of RPC that translates the call
to/from the remote model but I am not sure if Django provides such
primitive.

Cheers,
Ishwor


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Python Multiprocessing With Django

2009-03-06 Thread Jirka Vejrazka

> Thanks Jirka, that fixed the problem. But I think I will file a bug report
> that seem to be very hacky :)

Great, I'm glad it solved your problem. Personally, I don't think it
is a bug, as we both pushed Django well beyond its "area of
expertise". I really believe that Django is great for serving web
content and everyone (including) me trying to implement it in
different areas must be ready for problems and gotchas here and there.
But YMMV.

  Cheers

 Jirka

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



Re: Django and Python Warnings

2009-03-06 Thread Graham Dumpleton



On Mar 7, 2:53 am, Jacob Kaplan-Moss 
wrote:
> On Fri, Mar 6, 2009 at 9:46 AM, Brian Neal  wrote:
> > I updated my working copy of Django after a long period and was
> > browsing the source and noticed it was taking advantage of the Python
> > warnings module. What is the best way to "see" such warnings when
> > doing development? Is it possible to configure Python or the Django
> > development server to display such warning messages?
>
> You want the ``-W`` flag to the python binary; see ``python --help``
> for more. Essentially, you'll do::
>
>     python -Wall manage.py runserver

The issue of warnings came up recently in TG list, as apparent TG2
gets a load form third party packages it uses with newest versions of
Python.

Anyway, the issue is that at the moment mod_wsgi doesn't have an
equivalent for the command line -W option. Do people feel it would be
useful to have a directive in mod_wsgi which allows one to control the
warnings mechanism, ie., does the same as -W?

For Python 2.6 (in mod_wsgi 3.0), it already has a directive to enable
Py3K warnings, but not the -W option equivalent.

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



Re: Three Physical Tiers

2009-03-06 Thread ruffeo

I guess my question is how do you call a remote model object on a
different web server using Django MTV framework.



On Mar 5, 5:14 pm, Kevin Teague  wrote:
> On Mar 4, 12:21 pm, ruffeo  wrote:
>
> > Does anyone know how to develop a complex django project in a3tiered
> > network environment, still using the MCV architecture?
>
> > I.E. Web Server (view and control code), App Server (model code), and
> > Database Server
>
> You have to distinguish between "architecture" as it applies to
> different types of objects within a single process (also often called
> the MVC "pattern") and architecture as it applies to individual
> processes and how they communicate with each other. MVC isn't meant to
> describe the architecture between individual processes and how they
> communicate.
>
> If you want threephysicaltiers, each tier can have it's own MVC
> pattern (or each one can use a totally different pattern). If the "App
> Server" is a representation of the model and is only accessible by web
> services, then you need Django Models to represent the database model,
> and Django Views to expose those models via HTTP.
>
> Then the "Web Server" would have it's own Django Views which consult
> Django Models that are backed by web service calls. Finally you'd use
> Django Templates for most views to make it easier to separate the
> Python from the HTML. Finally the Views and Templates may themselves
> contain JavaScript, and that JavaScript code may organize itself into
> some MVC pattern ...
>
> Except Django tightly couples it's schema descriptions of models to a
> specific persistance layer. If you wanted to re-use the data
> description part of the model between relational database backed model
> classes and web service backed model classes, I'm not sure if it's
> possible - maybe it can be done with a little (or a lot) of
> metaclassery? Most likely you'd want to use an external package such
> as zope.schema to allow this further seperation of concerns.
>
> Except I'd say that both the MVC pattern and the Three teired
> architecture are both very simplisitic ways of modeling a web
> application. They tend to fall apart as you start to tailor them to
> what you are actually trying to build, the idea of separating the "Web
> Server" and "App Server" onto separatephysicalservers is kind of a
> clunky idea that was popular in the dot com era when you had to deploy
> onto 200 Mhz boxes. Today servers are fast enough that it's usually
> not an issue to deploy the whole stack on a single server ... but it
> all depends upon how big you want to scale up to - for example,
> Amazon.com makes this split between "Web/presentation" servers (using
> Perl/Mason) and "App/web-service-as-model" servers (using Java/SOAP),
> and that type of complexity is probably justified for the scale of
> their business.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django Resource Usage

2009-03-06 Thread Graham Dumpleton



On Mar 6, 10:45 pm, Paulo  wrote:
> Well, this leads me to an unknown path. Where i can find more
> information about how to install it and tweak it?

You still aren't saying how you intend to host it.

If you do not know, start by looking at the deployment mechanisms
supported by Django as explained in Django documentation.

Graham

> On 6 mar, 00:04, Graham Dumpleton  wrote:
>
> > On Mar 6, 1:24 pm, Malcolm Tredinnick 
> > wrote:
>
> > > On Thu, 2009-03-05 at 18:08 -0800, Paulo wrote:
> > > > Hi
>
> > > > I want to install Django on my webserver, but i would like to know
> > > > from you if django has an intense resource usage (memory, cpu) or it's
> > > > not a concern?
>
> > > As always, it depends on what you're doing. There simply *cannot* be any
> > > general answer to that question. That being said, typing "resource
> > > usage" into the search box on the django-users Google Groups page turns
> > > up a bunch of previous messages on this topic. Searching the archives
> > > will certainly give you some ideas of things to consider when
> > > benchmarking.
>
> > > The solution is always to profile and benchmark on your development
> > > systems before deploying.
>
> > It also depends on how you intend to deploy Django. If you try and run
> > it under mod_python or mod_wsgi embedded mode in Apache with prefork
> > MPM, then it can take huge amounts of memory. Even with worker MPM you
> > have to be careful and consider changing the default Apache MPM
> > settings as they default to be values more appropriate for static file
> > serving and PHP. Better deployment scenarios are mod_wsgi daemon mode
> > or fastcgi solutions with number of processes/threads used strictly
> > controlled.
>
> > So, how do you intend deploying it?
>
> > Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: ImportError: Could not import settings '.settings'.

2009-03-06 Thread Ishwor Gurung
Muslu Yüksektepe wrote:
>46  PythonPath "['*/home/hutch/apps/wikinotes/*'] + sys.path"
> 
> 
> try this code

[ ... ]

Apache returns 500 with that particular code. Anyway, it works already
(see my last post). Thanks in any case. ;)

Cheers,
Ishwor



smime.p7s
Description: S/MIME Cryptographic Signature


Re: Django Pluggable application for invoicing / accounts?

2009-03-06 Thread Adi Sieker
Hi,

there is also djime http://github.com/mikl/djime/tree/master though  
that leans more in the direction of hourly charges.

adi

On 06.03.2009, at 21:15, John Boxall wrote:

>
> Trolling through the board a bit here are some other postings on
> similar topics:
>
> Suggesting looking at Satchmo
> http://groups.google.com/group/django-users/browse_thread/thread/94ac6b1766a96208/e6b5f4189648bf53?lnk=gst=accounting#e6b5f4189648bf53
>
> Suggesting Beancounter:
> http://github.com/lincolnloop/django-beancounter/blob/736b627c337fdc2cab41f45375fd4eecbdd55526/beancounter/models.py
>
> Thanks,
>
> John
>
> On Mar 5, 4:36 pm, Malcolm Tredinnick 
> wrote:
>> On Thu, 2009-03-05 at 16:23 -0800, John Boxall wrote:
>>> Hey everyone,
>>
>>> I'm building a Django app that charges users monthly and one time
>>> fees. I need to generate invoices and keep track of orders and I  
>>> most
>>> definitely don't want to write this non-core code myself :) Someone
>>> else must have done it (or something like it!)
>>
>>> I've tried searching in the usual places but haven't found anything
>>> yet.
>>
>>> Has anyone seen any Django pluggable apps for maintaining billing
>>> history for users?
>>
>> No idea about the collecting of raw data stuff. It's likely only a
>> single model to record line items that you then summarise later  
>> when you
>> actually generate the reports. So that might be easy enough to just
>> knock up and even use the admin interface to populate.
>>
>> For the reporting side of things, you might want to look at Marinho
>> Brandão's Geraldo project. I looked at an early version of it and it
>> looked promising and sensibly designed (which sounds like damning  
>> with
>> faint praise, but I just haven't had time or motivation to dig deeper
>> into it. It's certainly on my list of apps to invest more time in).
>>
>> http://github.com/marinho/geraldo/tree/master
>>
>> Regards,
>> Malcolm
> 
--
Adi J. Sieker mobile: +49 - 178 - 88 5 88 13
Freelance developer   skype:  adijsieker
SAP-Consultantweb:http://www.sieker.info/profile
   openbc: https://www.openbc.com/hp/ 
AdiJoerg_Sieker/




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



Compressed fixtures?

2009-03-06 Thread Ben Davis
http://docs.djangoproject.com/en/dev/ref/django-admin/#compressed-fixtures

The docs say that you can use compressed fixtures, but I haven't gotten this
to work.  For example, I have myapp/fixtures/myfixture.yaml.gz,  but when I
run ./django-admin.py loaddata myapp/fixtures/myfixture.yaml,  it just exits
with no output, status of 0.

What am I doing wrong?

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



loaddata spewing to standard output but not actually loading

2009-03-06 Thread Serdar T.

Hey everyone,

While trying to load a json fixture, the contents are spitting out to
my bash shell but nothing is loading into the postgres database
backend.

>From inside my project directory, I'm executing the documented
command:

./manage.py loaddata data2.json

In addition to the contents, the only message I get from Django is:

"Installing json fixture 'data2' from absolute path."

But again, nothing is winding up in the database.

I should mention that this fixture was originally dumped from another
Django project. I renamed the Django app inside the fixture so that it
would match my new project (which otherwise has an identical schema).
While the updated fixture chokes, I'm able to successfully load a
fixture that was produced by after loading a portion of my data
manually thgrough the postgres backend.

Below are two slices from the fixture that works (budtype.json) and
the one that chokes (data2.json). Would love to hear if anyone has any
suggestions.

budtype.json#
#This fixture loads properly
1 [
2 {
3 "pk": 1,
4 "model": "reportcard.budtype",
5 "fields": {
6 "type": "K-6"
7 }
8 },
   <>

data2.json
#This fixture does not load
1 [
2 {
3 "pk": 1,
4 "model": "reportcard.budtype",
5 "fields": {
6 "type": "K-6"
7 }
8 },
<>

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



Re: Programmtically accessing properties on a model field?

2009-03-06 Thread Rajesh D

>
> I'm working on some code to scrub an images directory of anything not
> currently stored in the database, and would like to de-couple some
> things. I'm using signals, passing in an instance of a model that I
> would like to be able to grab some data from, namely, the 'upload_to'
> parameter of the ImageField in question.
>
> How can I access this property programmatically?
>
> If I'm passing in the instance of the object, I should be able to
> access the __class__ property of the object, but I can't seem to get
> to the 'upload_to' property on the field.

Try this:

c = instance.__class__ # where instance is your model object's
instance
img_field = c._meta.get_field_by_name('image')[0]
# In the above, substitute 'image' with your image field's name
upload_to = img_field.upload_to

Obviously, you can reduce all that to a one-liner once you understand
what this does.

-RD

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



Re: count and group by aggregation

2009-03-06 Thread kbs

returned an empty dict
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Optimizing my ORM query

2009-03-06 Thread Jeff Gentry

Sorry for the self-followup, but I got the right bits of extra.  My actual
case was a bit more complicated than my example below (it involved a
fourth model), but it's working now - and much quicker than w/ the IN
directive.  Thanks.

On Fri, 6 Mar 2009, Jeff Gentry wrote:

> On Fri, 6 Mar 2009, Malcolm Tredinnick wrote:
> > > Bob.objects.filter(foo=myFoo).filter(blah__in=myBlahs)
> > Seems like the best (and obvious) way to me.
> 
> Gotcha.
> 
> > Yes it does. As written, your models have no ordering requirements. That
> > complete lack of constraint is preserved perfectly. :-)
> 
> True ;)
> 
> > Precisely. If you want ordering, you have to specify it. The database is
> > in no way obliged to return rows even in the order they are stored on
> > disk, so if you're relying on that, you are making an error.
> 
> Fair enough, that's what I expected as I know that SQL IN isn't guaranteed
> to preserve anything.  I thought that there might be some chance that
> Django was doing something on top of that, but doubted it (and turned out
> to be right).
> 
> Here's a followup though.  To go back to my original model descriptions:
> 
>  class Foo:
> asdf = models.CharField()
> 
>  class Blah:
> qwerty = models.CharField()
> 
>  class Bob:
> foo = models.ForeignKey(Foo)
> blah = models.ForeignKey(Blah) 
> 
> Suppose that for a given Foo (say foo.id = 42), I want the Bobs associated
> with the entire set of Blahs.  In SQL I could do something like this
> (might not be exactly right, but should demonstrate the idea):
> 
> select * from app_bob,app_blah where app_bob.blah_id=app_blah.id and
> app_foo_id=42;
> 
> I'd imagine this would be faster than going through the IN directive
> (particularly considering that the entire set of Blahs will typically be
> 50k-250k in length).  I know that I can drop down to writing raw SQL
> queries but was trying to see if there was a way I could do something like
> this (if this is actually a smart query to do at all) via the ORM.  I'm
> currently looking at the extra() command but can't seem to get the right
> mojo to get that working.
> 
> What's the right way to get this one working?
> 
> Thanks
> -J
> 
> 
> 


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



Re: manage.py dumpdata app.model doesn't seem to work?

2009-03-06 Thread Alex Koshelev
This `dumpdata` command you can only serialize whole application not just
its models.


On Fri, Mar 6, 2009 at 11:17 PM, John M  wrote:

>
> I tried using the command
>
> $ python manage.py dumpdata app.model.
>
> where app is the name of my application and model is one of it's
> models, I didn't actually use the names app and model.
>
> I get the following error:
>
> django.core.exceptions.ImproperlyConfigured: App with labelapp.model
> could not be found.
>
> I'm running 1.1 alpha 1.
>
> Thoughts?
>
> I'd love to be able to dump the data for just one table and then
> reload it.
>
> Thanks
>
> John
> >
>

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



Re: count and group by aggregation

2009-03-06 Thread Alex Koshelev
Try this:

R.objects.values('type').aggregate(Count('type'))


On Fri, Mar 6, 2009 at 10:12 PM, kbs  wrote:

>
> Hello,
>
> I got a model with a type field
>
> 
> class R(mode):
>type = CharField(max_length=100)
> 
>
> Here is what im trying to do using sql notation:
>
> 
> SELECT typ,count(*) FROM R GROUP BY type
> 
>
> The following
> 
> R.objects.aggregate(Count('type'))
> 
>
> returns the same result as
>
> 
> SELECT count(*) R
> 
>
> is it possible with a one liner using django qs syntax?
>
> 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-users@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
-~--~~~~--~~--~--~---



forms.ModelForm

2009-03-06 Thread mike171562

I am using Django's ModelForm in a template im working on. I am trying
to use it to display the Django User Object and an extension I added
of the user model, what would be the correct way to display my User
model extension in my template, I would like to be able to edit the
User information and the account number I have added all from the same
form. Thanks.

class UserModelForm(forms.ModelForm):
class Meta:
model = User
fields = ('username','first_name','last_name',
 
'password_field','email','account','is_superuser','is_staff')


@staff_member_required
def create_edit_users(request, id=None):
user = request.user
tick_num = Ticket.objects.filter(status__contains='Open').count()
if id is not None:
puser = get_object_or_404(User, pk=id)
else:
puser = None
form = UserModelForm(data=request.POST or None, instance=puser)

if form.is_valid():
form.save()
return HttpResponseRedirect("/users/")

return render_to_response("user.php", {'form':form},RequestContext
(request))


My extension of the User model is as follows

class Account_Number(models.Model):
account_number = models.CharField(max_length=8)
user = models.ForeignKey(User, unique=True)
userfield = models.NullBooleanField(null=True, blank=True)
def __str__(self):
  return self.account_number
class Admin:
list_display = ('account_number','userfield')

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



manage.py dumpdata app.model doesn't seem to work?

2009-03-06 Thread John M

I tried using the command

$ python manage.py dumpdata app.model.

where app is the name of my application and model is one of it's
models, I didn't actually use the names app and model.

I get the following error:

django.core.exceptions.ImproperlyConfigured: App with labelapp.model
could not be found.

I'm running 1.1 alpha 1.

Thoughts?

I'd love to be able to dump the data for just one table and then
reload it.

Thanks

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



Re: Django Pluggable application for invoicing / accounts?

2009-03-06 Thread John Boxall

Trolling through the board a bit here are some other postings on
similar topics:

Suggesting looking at Satchmo
http://groups.google.com/group/django-users/browse_thread/thread/94ac6b1766a96208/e6b5f4189648bf53?lnk=gst=accounting#e6b5f4189648bf53

Suggesting Beancounter:
http://github.com/lincolnloop/django-beancounter/blob/736b627c337fdc2cab41f45375fd4eecbdd55526/beancounter/models.py

Thanks,

John

On Mar 5, 4:36 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-03-05 at 16:23 -0800, John Boxall wrote:
> > Hey everyone,
>
> > I'm building a Django app that charges users monthly and one time
> > fees. I need to generate invoices and keep track of orders and I most
> > definitely don't want to write this non-core code myself :) Someone
> > else must have done it (or something like it!)
>
> > I've tried searching in the usual places but haven't found anything
> > yet.
>
> > Has anyone seen any Django pluggable apps for maintaining billing
> > history for users?
>
> No idea about the collecting of raw data stuff. It's likely only a
> single model to record line items that you then summarise later when you
> actually generate the reports. So that might be easy enough to just
> knock up and even use the admin interface to populate.
>
> For the reporting side of things, you might want to look at Marinho
> Brandão's Geraldo project. I looked at an early version of it and it
> looked promising and sensibly designed (which sounds like damning with
> faint praise, but I just haven't had time or motivation to dig deeper
> into it. It's certainly on my list of apps to invest more time in).
>
> http://github.com/marinho/geraldo/tree/master
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Equivalent of postgresql coalesce for sqllite

2009-03-06 Thread madhav

I found an answer to my own question. The answer is here:http://
stackoverflow.com/questions/620156/equivalent-of-postgresql-coalesce-
for-sqllite

On Mar 7, 12:52 am, madhav  wrote:
> This may sound more like a sql question but I got this error in the
> django context. And I presume django users would have solved this
> issue, So I am posting it here. I am using postgresql_psycopg2 engine
> for my production db, but the test runner uses sqllite3 for running
> the tests. Keeping my production db(postgresql)in mind I tried
> building a query which uses "coalesce". But sqllite3 doesn't recognize
> this. How do I get pass this. I can use postgresql_psycopg2 even for
> my test running(just to avoid wastage of time), but its too slow. How
> do I get pass this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Optimizing my ORM query

2009-03-06 Thread Sebastian Bauer
W dniu 06.03.2009 20:06, Jeff Gentry pisze:
> On Fri, 6 Mar 2009, Malcolm Tredinnick wrote:
>
>>> Bob.objects.filter(foo=myFoo).filter(blah__in=myBlahs)
>>>
>> Seems like the best (and obvious) way to me.
>>  
>
> Gotcha.
>
>
>> Yes it does. As written, your models have no ordering requirements. That
>> complete lack of constraint is preserved perfectly. :-)
>>  
>
> True ;)
>
>
>> Precisely. If you want ordering, you have to specify it. The database is
>> in no way obliged to return rows even in the order they are stored on
>> disk, so if you're relying on that, you are making an error.
>>  
>
> Fair enough, that's what I expected as I know that SQL IN isn't guaranteed
> to preserve anything.  I thought that there might be some chance that
> Django was doing something on top of that, but doubted it (and turned out
> to be right).
>
> Here's a followup though.  To go back to my original model descriptions:
>
>   class Foo:
>  asdf = models.CharField()
>
>   class Blah:
>  qwerty = models.CharField()
>
>   class Bob:
>  foo = models.ForeignKey(Foo)
>  blah = models.ForeignKey(Blah)
>
> Suppose that for a given Foo (say foo.id = 42), I want the Bobs associated
> with the entire set of Blahs.  In SQL I could do something like this
> (might not be exactly right, but should demonstrate the idea):
>
> select * from app_bob,app_blah where app_bob.blah_id=app_blah.id and
> app_foo_id=42;
>
> I'd imagine this would be faster than going through the IN directive
> (particularly considering that the entire set of Blahs will typically be
> 50k-250k in length).  I know that I can drop down to writing raw SQL
> queries but was trying to see if there was a way I could do something like
> this (if this is actually a smart query to do at all) via the ORM.  I'm
> currently looking at the extra() command but can't seem to get the right
> mojo to get that working.
>
> What's the right way to get this one working?
>
> Thanks
> -J
>
this supposed to work:

blah_subquery="blah_id IN (%s)" %  
Blah.objects.values("id").filter(qwerty__icontains='somethink').query
Bob.objects.filter(foo=myFoo).extra(where=blah_subquery)


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



Failures in auth.tests.views.ChangePasswordTest on trunk

2009-03-06 Thread Brett Hoerner

Has anyone else seen this?  Running tests with django.contrib.*
installed on r9983.  I just want to make sure I'm not doing something
stupid here before I investigate a further.  It's certainly possible
because I see no tickets or relevant matches on the lists.

http://dpaste.com/8094/

Creation of spatial database test_thingy successful.
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_comments
Creating table django_comment_flags
Creating table django_content_type
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_site
Installing index for admin.LogEntry model
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for comments.Comment model
Installing index for comments.CommentFlag model
Installing index for flatpages.FlatPage model
Installing index for redirects.Redirect model
FFF.
==
FAIL: test_password_change_fails_with_invalid_old_password
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/a/thingy/src/current/python/django/contrib/auth/tests/
views.py", line 138, in
test_password_change_fails_with_invalid_old_password
self.assertEquals(response.status_code, 200)
AssertionError: 403 != 200

==
FAIL: test_password_change_fails_with_mismatched_passwords
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/a/thingy/src/current/python/django/contrib/auth/tests/
views.py", line 149, in
test_password_change_fails_with_mismatched_passwords
self.assertEquals(response.status_code, 200)
AssertionError: 403 != 200

==
FAIL: test_password_change_succeeds
(django.contrib.auth.tests.views.ChangePasswordTest)
--
Traceback (most recent call last):
  File "/a/thingy/src/current/python/django/contrib/auth/tests/
views.py", line 160, in test_password_change_succeeds
self.assertEquals(response.status_code, 302)
AssertionError: 403 != 302

--
Ran 36 tests in 1.062s

FAILED (failures=3)
Destroying test database...

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



Equivalent of postgresql coalesce for sqllite

2009-03-06 Thread madhav

This may sound more like a sql question but I got this error in the
django context. And I presume django users would have solved this
issue, So I am posting it here. I am using postgresql_psycopg2 engine
for my production db, but the test runner uses sqllite3 for running
the tests. Keeping my production db(postgresql)in mind I tried
building a query which uses "coalesce". But sqllite3 doesn't recognize
this. How do I get pass this. I can use postgresql_psycopg2 even for
my test running(just to avoid wastage of time), but its too slow. How
do I get pass this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Python Multiprocessing With Django

2009-03-06 Thread Vitaly Babiy
Thanks Jirka, that fixed the problem. But I think I will file a bug report
that seem to be very hacky :)

Vitaly Babiy


On Fri, Mar 6, 2009 at 11:15 AM, Vitaly Babiy  wrote:

> Alright I will have to give this a try
>
> Vitaly Babiy
>
>
>
> On Fri, Mar 6, 2009 at 10:30 AM, Jirka Vejrazka 
> wrote:
>
>>
>> > I have a management command that that starts up a few process to process
>> a
>> > request: http://dpaste.com/7925/.
>>
>> Hi, I was recently debugging similar issue and came to a conclusion
>> (which may be wrong of course :)  that multiprocessing and Django DB
>> connections don't play well together. I ended up closing Django DB
>> connection first thing in the new process. It'll recreate a new
>> connection when it needs one, but that one will have no references to
>> the connection used by the parent.
>>
>> So, my Process.start() calls a function which starts with:
>> >>> from django.db import connection
>> >>> connection.close()
>>
>>  This solved my problem.
>>
>>   Cheers
>>
>> Jirka
>>
>> >>
>>
>

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



count and group by aggregation

2009-03-06 Thread kbs

Hello,

I got a model with a type field


class R(mode):
type = CharField(max_length=100)


Here is what im trying to do using sql notation:


SELECT typ,count(*) FROM R GROUP BY type


The following

R.objects.aggregate(Count('type'))


returns the same result as


SELECT count(*) R


is it possible with a one liner using django qs syntax?

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-users@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
-~--~~~~--~~--~--~---



ajax request is missing default values for inputs?

2009-03-06 Thread Aaron Newton

Hi all,

First time caller and a total noob to django (not new to development/
programming or anything though).

Have this bizarre thing going on. When I request a form (using the
FormsWizard) with my browser, everything works great. Specifically,
the input initial value is present:

forms.IntegerField(label="Gimme a number", initial=1)

renders:


Re: Optimizing my ORM query

2009-03-06 Thread Jeff Gentry

On Fri, 6 Mar 2009, Malcolm Tredinnick wrote:
> > Bob.objects.filter(foo=myFoo).filter(blah__in=myBlahs)
> Seems like the best (and obvious) way to me.

Gotcha.

> Yes it does. As written, your models have no ordering requirements. That
> complete lack of constraint is preserved perfectly. :-)

True ;)

> Precisely. If you want ordering, you have to specify it. The database is
> in no way obliged to return rows even in the order they are stored on
> disk, so if you're relying on that, you are making an error.

Fair enough, that's what I expected as I know that SQL IN isn't guaranteed
to preserve anything.  I thought that there might be some chance that
Django was doing something on top of that, but doubted it (and turned out
to be right).

Here's a followup though.  To go back to my original model descriptions:

 class Foo:
asdf = models.CharField()

 class Blah:
qwerty = models.CharField()

 class Bob:
foo = models.ForeignKey(Foo)
blah = models.ForeignKey(Blah) 

Suppose that for a given Foo (say foo.id = 42), I want the Bobs associated
with the entire set of Blahs.  In SQL I could do something like this
(might not be exactly right, but should demonstrate the idea):

select * from app_bob,app_blah where app_bob.blah_id=app_blah.id and
app_foo_id=42;

I'd imagine this would be faster than going through the IN directive
(particularly considering that the entire set of Blahs will typically be
50k-250k in length).  I know that I can drop down to writing raw SQL
queries but was trying to see if there was a way I could do something like
this (if this is actually a smart query to do at all) via the ORM.  I'm
currently looking at the extra() command but can't seem to get the right
mojo to get that working.

What's the right way to get this one working?

Thanks
-J



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



Programmtically accessing properties on a model field?

2009-03-06 Thread Brandon Taylor

Hi everyone,

I'm working on some code to scrub an images directory of anything not
currently stored in the database, and would like to de-couple some
things. I'm using signals, passing in an instance of a model that I
would like to be able to grab some data from, namely, the 'upload_to'
parameter of the ImageField in question.

How can I access this property programmatically?

If I'm passing in the instance of the object, I should be able to
access the __class__ property of the object, but I can't seem to get
to the 'upload_to' property on the field.

TIA,
Brandon

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



For Chinese Django users

2009-03-06 Thread usr . root

Hi guys,

My company planed to develop a game with Python, the whole product is
planned to write in python, including build the website with Django.

I have build a technology bbs yesterday, the topic is set to game and
website developing with python.

You can join us if you have any interest.

Because this bbs is build in Chinese language, Chinese reading ability
is needed.

Our website: http://xianshionline.5d6d.com/


Best Wishes,
Feng

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



Re: Inserting Into Cleaned_Data Inside a ModelForm

2009-03-06 Thread rajeesh

You may change the save_model() method of corresponding AdminClass for
that:
e.g, to set the attribute 'a' of model 'Book' , write inside
BookAdmin.save_model() something like this:

obj.a = form.cleaned_data['another_key'] * 2
obj.save()

On Mar 6, 8:43 pm, Waldemar Kornewald  wrote:
> On 6 Mrz., 14:13, Chris  wrote:
>
> > I have a model that has a required attribute, but I want this
> > attribute set to a calculated value based on the input from a form. So
> > inside the save() method of my ModelForm class, I'm doing:
>
> > self.cleaned_data['requiredKey'] = 123
> > record = forms.ModelForm.save(self)


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



Re: opposite of icontains

2009-03-06 Thread koranthala



On Mar 6, 9:15 pm, Jeff FW  wrote:
> Clearly, you get to work on cooler projects than I :-)  I had thought
> of the keywords/phrases case, but the other ones are far more
> interesting.  Thanks for the explanation!
>
> -Jeff
>
> On Mar 5, 7:02 pm, Malcolm Tredinnick 
> wrote:
>
> > On Thu, 2009-03-05 at 12:54 -0800, Jeff FW wrote:
> > > Well, then, that is quite a strange use case :-)  Nevermind my simple
> > > methods.  Malcom's suggestion of an extension for postgres seems like
> > > a good idea--writing functions in various languages (like Python!) is
> > > _really_ easy in postgres.
>
> > > Just out of curiosity (for either of you,) what is a search like that
> > > used for?  I've had a lot of strange requests from a lot of (generally
> > > strange) clients, but that's a pretty weird one.
>
> > It's not that weird at all. It simply depends on the domains you're
> > working in. No idea how it might apply to article headlines, although
> > finding "related matches" could well use something like this.
>
> > It's very common for finding overlaps in sequences of strings, though.
> > The almost "standard" example is DNA sequences where you're trying to
> > find if one sequenced set of data (bases extracted from a genetic
> > sample) correspond to anything else already in the database. Since there
> > can be damage at the extremeties of extractions, or even in the middle
> > (or mutations), finding the longest common substring is the standard
> > approach. There's a whole related area of reasearch in finding the
> > longest palindrome sequences, too, for similar matching and folding
> > purposes.
>
> > Plagarism or even "similar article" testing is another case like this.
> > Finding all "reasonably long" common sequences between a set of source
> > documents and a candidate document is a start.
>
> > One case I built something for was a compressed storage and
> > transmissiong system for PDF and ODF documents. That required doing,
> > essentially, a context-aware diff'ing process and pulling out any large
> > chunks of commonality was the first step.
>
> > Finally, not quite the same problem, but highly related, is the issue
> > of, say, quickly finding all tags or other keywords or phrases that
> > appear in a collection documents. Sometimes partial matching is an
> > appropriate place for generating new phrases, so a modified Aho-Corasick
> > search (just to give you a term to search on if you care) is a starting
> > point.
>
> > This whole domain is a very interesting area for algorithms and
> > implementation.
>
> > Regards,
> > Malcolm

I used the headline example since icontains in Django documentation
was showing that example.
Mine is a case where string search from document text matches specific
values in stored data.
The document in my case, even though text, contained directories,
basic text, and many other similar cases.
The string stored might be a path of the directory - or even a single
piece of text.
So, mine is a very usual case, not at all close to exotic as Malcolm's.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Custom filter() operators

2009-03-06 Thread Jay Deiman

Malcolm Tredinnick wrote:
> On Fri, 2009-03-06 at 08:00 +0900, Russell Keith-Magee wrote:
> [...]
>> However, I agree that this would be a useful feature to add (or
>> improve). This isn't something we want to be trivial to accomplish,
>> but it should be a lot easier for people who are adding fields that
>> have unusual operator requirements. I haven't dug into the details to
>> work out exactly how we would approach this - any proposals are
>> welcome, especially if you can work through the details to see what
>> might be possible.
> 
> It's certainly on my long-term list (but no closer than that at the
> moment). The hard part is keeping the Field classes and the database
> storage layer reasonably separate. If people want to combine the two in
> their own custom Field classes, that's fine, but I don't want to
> introduce even tighter coupling than we already have in Django (there's
> some leakage of SQL-awareness into the Field layer, but it's minimal),
> because the idea is to make it easy to replace the SQL storage with
> something else. So it's the internal API that is the largely non-trivial
> part.
> 
> Right now, the easiest way to do this stuff is to forget about doing it
> as a custom lookup type and do it as a custom Q-like object. Then you
> could write something like
> 
> Foo.objects.filter(CIDR('my_field', '1.2.3.4'))
> 
> Here, CIDR is something like a Q class. Have a look at
> django.db.models.sql.Query.add_q() for how anything with add_to_query()
> and as_sql() methods are handled.

Well, as it stands now, I just patched the Django 1.0.2-final source to 
add the necessary lookups, which is below for any who are interested. 
Keep in mind this was a simple patch to just add the functionality I 
need for my current project, not necessarily "top notch" work.

My long term plan, when I finish my current project is to submit this 
patch, plus my InetField and CidrField (and their related form field 
subclasses), to the project.  I plan to make this backend independent by 
defaulting to a CharField for any backend, other than Postgres, on these 
two fields.  This would at least make these (very useful) types 
available to all.  Since I will be using these quite extensively within 
my current project, I will be able to do code tweaking and testing, as 
well as some actual documentation, before submitting these to the Django 
upstream for inclusion.

As noted previously, I think there would be a great benefit to allowing 
the easy addition of custom db filters and I would be happy to help out 
with this after my current project I'm working on.

Thanks for the help and suggestions,

Jay

-- 
Jay Deiman

\033:wq!

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



Model design question

2009-03-06 Thread tdelam

Hi Everyone,

I recently put a new design to a web site. The web site is static
basically aside from some content changes every now and then. The
navigation is static, there will never be any addition to this. Each
section will have a sub-section though. Also, MAYBE in the future a
new sub-section may get introduced. So /about/ will have some /about/
company or /about/our-team/ and so on What would be the best way
to model this? I don't want the main nav to be dynamic but I do have
some sub sections per nav item. Sounds like maybe I have no choice but
to make the nav dynamic and relate sub sections to those.

Anyway, suggestions are appreciated :)

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



Re: Why are views not called controllers?

2009-03-06 Thread Jacob Kaplan-Moss

Also see: 
http://www.pointy-stick.com/blog/2008/11/30/removing-model-view-controller-straitjacket/

Jacob

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



Re: Why are views not called controllers?

2009-03-06 Thread Karen Tracey
On Fri, Mar 6, 2009 at 11:37 AM, chyld.medf...@gmail.com <
chyld.medf...@gmail.com> wrote:

>
> I'm new to django, but have experience with asp.net mvc.  In asp.net
> mvc, controllers receive and process the request from the user and
> then once the data is ready to present, it's handed off to a view.  In
> django a view receives and processes the request and then sends the
> data to a template to render.  Basically the same thing is happening
> in both frameworks, but since django is using the model-view-
> controller pattern, why are the controllers called views and the
> templates called views?
>

http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

Karen

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



Re: Why are views not called controllers?

2009-03-06 Thread Masklinn

On 6 Mar 2009, at 17:37 , chyld.medf...@gmail.com wrote:
> I'm new to django, but have experience with asp.net mvc.  In asp.net
> mvc, controllers receive and process the request from the user and
> then once the data is ready to present, it's handed off to a view.  In
> django a view receives and processes the request and then sends the
> data to a template to render.  Basically the same thing is happening
> in both frameworks, but since django is using the model-view-
> controller pattern, why are the controllers called views and the
> templates called views?
>
> Thanks,
> -Chyld

http://docs.djangoproject.com/en/dev/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

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



Why are views not called controllers?

2009-03-06 Thread chyld.medf...@gmail.com

I'm new to django, but have experience with asp.net mvc.  In asp.net
mvc, controllers receive and process the request from the user and
then once the data is ready to present, it's handed off to a view.  In
django a view receives and processes the request and then sends the
data to a template to render.  Basically the same thing is happening
in both frameworks, but since django is using the model-view-
controller pattern, why are the controllers called views and the
templates called views?

Thanks,
-Chyld

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



Re: Why serializing to JSON doesn't work?

2009-03-06 Thread Jeff FW

Keep the way you're serializing the querysets, add each one to a
dictionary, and then:

return dict((k, simplejson.dumps(v)) for k, v in ret_val.iteritems())

-Jeff

On Mar 6, 10:49 am, Marek Wawrzyczek  wrote:
> Thanks for your responses, they helped :)
>
> In the code below:
>
>        ret['b'] = State.objects.all()
>             print 'ret: %' % ret
>             try:
>                 serialized = encoder.JSONEncoder().encode(ret)
>             except Exception, e:
>                 print 'exception: %s' % e
>
> I was doing the following mistake - I wanted to serialize query set in a
> dictionary directly, and the exception was thrown, I think because
> encoder.JSONEncoder() can't encode a QuerySet.
>
> While using code like this:
>
>          ret = State.objects.all()
>          json_serializer = serializers.get_serializer("json")()
>          serialized_model = json_serializer.serialize(ret, ensure_ascii = 
> False)
>          ret_val['b'] = serialized_model
>          serialized = encoder.JSONEncoder().encode(ret_val)
>
> then it doesn't throw exception, but code above just creates a
> serialized dicionary of serialized model, so when I try to decode it
> with JSON parser on a page, i get a dictionary of strings. I can create
> a JSON response manually by:
>
>     serialized = '{"b":%s}'% serialized_model
>
> but it's a little annoying while serializing a few models.
>
> Is there any way to serialize dictionary of QuerySets without creating
> json response manually?
>
> Regards,
> Marek
>
> > You know what's weird?  I've used simplejson.dumps() plenty of times
> > in my own code... not sure why that one just slipped out of my
> > memory.  I should just stop responding to things  :-)
>
> > Anyway, since you're serializing a model, you *should* be using your
> > originally posted method.  Use the way Marek said for anything other
> > than models (of course, the object has to be serializable.)
>
> > If that doesn't work, post the full (relevant) code.
>
> > -Jeff
>
> > On Mar 5, 7:01 am, Marek Wawrzyczek  wrote:
>
> >> > Thomas Guettler wrote:
>
> >>> > > Jeff FW schrieb:
>
>  > >> The serializers are for serializing querysets/models.  I'm surprised
>  > >> you're not getting an error message there--are you catching all
>  > >> exceptions?
>
>  > >> What you want is in django.utils.simplejson:
>
>  > >> from django.utils.simplejson import encoder
>  > >> encoder.JSONEncoder().encode(ret)
>
> >>> > > Or this:
>
> >> >  from django.utils import simplejson
> >> >  simplejson.dumps(...)
>
> >>> > > But unfortunately this does not encode datetime objects.
>
> >>> > >   Thomas
>
> >> > Thanks for your responses. Now when I try
>
> >> >      ret = { }
> >> >      ret['a'] = 'b'
> >> >      serialized = encoder.JSONEncoder().encode(ret)
> >> >      print serialized
>
> >> > then It works.
>
> >> > But now I have another problem. I have a class "State":
>
> >> > class State(models.Model):
> >> >     state = models.CharField(max_length = 30)
>
> >> >     def __unicode__(self):
> >> >         return self.state
>
> >> > Throutht the admin page I create a state called "Slaskie".      
> >> > Then the code :
>
> >> >             ret['b'] = State.objects.all()
> >> >             print 'ret: %' % ret
> >> >             try:
> >> >                 serialized = encoder.JSONEncoder().encode(ret)
> >> >             except Exception, e:
> >> >                 print 'exception: %s' % e
>
> >> > returns the output:
>
> >> >     {'b': []}
> >> >     [] is not JSON serializable
>
> >> > At the 
> >> > pagehttp://docs.djangoproject.com/en/dev/topics/serialization/#id2there's
> >> > written something about unicode and lazy translation. I tried to use
>
> >> >     le = LazyEncoder()       #lazy encoder is a given class from the
> >> > link above
> >> >     serialized = le.encode(ret)
>
> >> > and then the exception was:
> >> >     Circular reference detected
>
> >> > when I tried
>
> >> >     le = LazyEncoder (ensure_ascii = False)
>
> >> > the exception was the same:
> >> >     Circular reference detected
>
> >> > What's going on with this lazy translation and unicode ? How can I
> >> > serialize the data correctly ?
>
> >> > Regards,
> >> > Marek
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django setup problem when executing syncdb

2009-03-06 Thread bitra

Thanks Karen,
oops, I forgot to mention, yes I'm using Windows and had the same "No
module named Mysqldb" error message...

I'm checking the link you gave and I'll try it out.

Thanks again. :)


On Mar 6, 11:05 pm, Karen Tracey  wrote:
> On Fri, Mar 6, 2009 at 10:54 AM, bitra  wrote:
>
> > Hi, I had the same problem with ches. I install mysql with Django
> > 1.0.2 and given the same error message, but I was using Python 2.5.2.
> > Do I have to install mysqldb module for this Python version?
>
> Yes.  You have to install a mysqldb built against Python 2.5 if you want to
> run with MySQL and any Python 2.5.x.   If you're on Windows (I don't know if
> the 'ches' you mention is an OS or an app or what) you can find Windows
> binaries for Python 2.4 and 2.5 here:
>
> http://sourceforge.net/project/showfiles.php?group_id=22307_i...
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Python Multiprocessing With Django

2009-03-06 Thread Vitaly Babiy
Alright I will have to give this a try

Vitaly Babiy


On Fri, Mar 6, 2009 at 10:30 AM, Jirka Vejrazka wrote:

>
> > I have a management command that that starts up a few process to process
> a
> > request: http://dpaste.com/7925/.
>
> Hi, I was recently debugging similar issue and came to a conclusion
> (which may be wrong of course :)  that multiprocessing and Django DB
> connections don't play well together. I ended up closing Django DB
> connection first thing in the new process. It'll recreate a new
> connection when it needs one, but that one will have no references to
> the connection used by the parent.
>
> So, my Process.start() calls a function which starts with:
> >>> from django.db import connection
> >>> connection.close()
>
>  This solved my problem.
>
>   Cheers
>
> Jirka
>
> >
>

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



Re: opposite of icontains

2009-03-06 Thread Jeff FW

Clearly, you get to work on cooler projects than I :-)  I had thought
of the keywords/phrases case, but the other ones are far more
interesting.  Thanks for the explanation!

-Jeff

On Mar 5, 7:02 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-03-05 at 12:54 -0800, Jeff FW wrote:
> > Well, then, that is quite a strange use case :-)  Nevermind my simple
> > methods.  Malcom's suggestion of an extension for postgres seems like
> > a good idea--writing functions in various languages (like Python!) is
> > _really_ easy in postgres.
>
> > Just out of curiosity (for either of you,) what is a search like that
> > used for?  I've had a lot of strange requests from a lot of (generally
> > strange) clients, but that's a pretty weird one.
>
> It's not that weird at all. It simply depends on the domains you're
> working in. No idea how it might apply to article headlines, although
> finding "related matches" could well use something like this.
>
> It's very common for finding overlaps in sequences of strings, though.
> The almost "standard" example is DNA sequences where you're trying to
> find if one sequenced set of data (bases extracted from a genetic
> sample) correspond to anything else already in the database. Since there
> can be damage at the extremeties of extractions, or even in the middle
> (or mutations), finding the longest common substring is the standard
> approach. There's a whole related area of reasearch in finding the
> longest palindrome sequences, too, for similar matching and folding
> purposes.
>
> Plagarism or even "similar article" testing is another case like this.
> Finding all "reasonably long" common sequences between a set of source
> documents and a candidate document is a start.
>
> One case I built something for was a compressed storage and
> transmissiong system for PDF and ODF documents. That required doing,
> essentially, a context-aware diff'ing process and pulling out any large
> chunks of commonality was the first step.
>
> Finally, not quite the same problem, but highly related, is the issue
> of, say, quickly finding all tags or other keywords or phrases that
> appear in a collection documents. Sometimes partial matching is an
> appropriate place for generating new phrases, so a modified Aho-Corasick
> search (just to give you a term to search on if you care) is a starting
> point.
>
> This whole domain is a very interesting area for algorithms and
> implementation.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django setup problem when executing syncdb

2009-03-06 Thread Karen Tracey
On Fri, Mar 6, 2009 at 10:54 AM, bitra  wrote:

>
> Hi, I had the same problem with ches. I install mysql with Django
> 1.0.2 and given the same error message, but I was using Python 2.5.2.
> Do I have to install mysqldb module for this Python version?
>

Yes.  You have to install a mysqldb built against Python 2.5 if you want to
run with MySQL and any Python 2.5.x.   If you're on Windows (I don't know if
the 'ches' you mention is an OS or an app or what) you can find Windows
binaries for Python 2.4 and 2.5 here:

http://sourceforge.net/project/showfiles.php?group_id=22307_id=15775

Karen

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



Re: Django setup problem when executing syncdb

2009-03-06 Thread bitra

Hi, I had the same problem with ches. I install mysql with Django
1.0.2 and given the same error message, but I was using Python 2.5.2.
Do I have to install mysqldb module for this Python version?

thanks,


On Mar 1, 6:18 am, AKK  wrote:
> If you have windows you may want to try this version
>
> http://groups.google.com/group/django-users/msg/5b5f4dee148d0fc3
>
> There wasn't an mysqldb module exe version available for python 2.6
> when i looked a few weeks ago.
> I installed that and its worked fine.
>
> Andrew
>
> On 28 Feb, 14:23, ches  wrote:
>
> > Dear All,
> > I haveinstallPython2.6,Django 1.0.2, I'm sure it is installed
> > ok,since there is no errors on "import django" from the
> > interpreter,however when executingsyncdb, I got:
>
> > C:\Django\projects\documenti>manage.pysyncdb
> > Traceback (most recent call last):
> >   File "C:\Django\projects\documenti\manage.py", line 11, in 
> >     execute_manager(settings)
> >   File "C:\Python26\lib\site-packages\django\core\management
> > \__init__.py", line
> > 340, in execute_manager
> >     utility.execute()
> >   File "C:\Python26\lib\site-packages\django\core\management
> > \__init__.py", line
> > 295, in execute
> >     self.fetch_command(subcommand).run_from_argv(self.argv)
> >   File "C:\Python26\lib\site-packages\django\core\management\base.py",
> > line 192,
> >  in run_from_argv
> >     self.execute(*args, **options.__dict__)
> >   File "C:\Python26\lib\site-packages\django\core\management\base.py",
> > line 218,
> >  in execute
> >     self.validate()
> >   File "C:\Python26\lib\site-packages\django\core\management\base.py",
> > line 246,
> >  in validate
> >     num_errors = get_validation_errors(s, app)
> >   File "C:\Python26\lib\site-packages\django\core\management
> > \validation.py", lin
> > e 22, in get_validation_errors
> >     from django.db import models, connection
> >   File "C:\Python26\lib\site-packages\django\db\__init__.py", line 16,
> > in  > e>
> >     backend = __import__('%s%s.base' % (_import_path,
> > settings.DATABASE_ENGINE),
> >  {}, {}, [''])
> >   File "C:\Python26\lib\site-packages\django\db\backends\mysql
> > \base.py", line 13
> > , in 
> >     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No mo
> > dule named MySQLdb
>
> > Do you have an idea?
>
> > Kind Regards,
> >    ches

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



Re: template include and for loop speed

2009-03-06 Thread Jacob Kaplan-Moss

On Fri, Mar 6, 2009 at 4:25 AM, Thierry  wrote:
> Why is an include tag so much heavier on the template system?

Because it has to search for the given template on the file system.
Depending on how you've got TEMPLATE_LOADERS and TEMPLATE_DIRS set,
this could search in dozens of places.

Jacob

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



Re: Why serializing to JSON doesn't work?

2009-03-06 Thread Marek Wawrzyczek

Thanks for your responses, they helped :)

In the code below:

   ret['b'] = State.objects.all()
print 'ret: %' % ret
try:
serialized = encoder.JSONEncoder().encode(ret)
except Exception, e:
print 'exception: %s' % e

I was doing the following mistake - I wanted to serialize query set in a
dictionary directly, and the exception was thrown, I think because
encoder.JSONEncoder() can't encode a QuerySet.

While using code like this:

 ret = State.objects.all()
 json_serializer = serializers.get_serializer("json")()
 serialized_model = json_serializer.serialize(ret, ensure_ascii = False)
 ret_val['b'] = serialized_model
 serialized = encoder.JSONEncoder().encode(ret_val)

then it doesn't throw exception, but code above just creates a
serialized dicionary of serialized model, so when I try to decode it
with JSON parser on a page, i get a dictionary of strings. I can create
a JSON response manually by:

serialized = '{"b":%s}'% serialized_model

but it's a little annoying while serializing a few models.

Is there any way to serialize dictionary of QuerySets without creating
json response manually?

Regards,
Marek

> You know what's weird?  I've used simplejson.dumps() plenty of times
> in my own code... not sure why that one just slipped out of my
> memory.  I should just stop responding to things  :-) 
>
> Anyway, since you're serializing a model, you *should* be using your
> originally posted method.  Use the way Marek said for anything other
> than models (of course, the object has to be serializable.)
>
> If that doesn't work, post the full (relevant) code.
>
> -Jeff
>
> On Mar 5, 7:01 am, Marek Wawrzyczek  wrote:
>   
>> > Thomas Guettler wrote:
>> >
>> 
>>> > > Jeff FW schrieb:
>>>   
>> >
>> 
 > >> The serializers are for serializing querysets/models.  I'm surprised
 > >> you're not getting an error message there--are you catching all
 > >> exceptions?
 
>> >
>> 
 > >> What you want is in django.utils.simplejson:
 
>> >
>> 
 > >> from django.utils.simplejson import encoder
 > >> encoder.JSONEncoder().encode(ret)
 
>> >
>> 
>>> > > Or this:
>>>   
>> >
>> 
>> >  from django.utils import simplejson
>> >  simplejson.dumps(...)
>> 
>> >
>> 
>>> > > But unfortunately this does not encode datetime objects.
>>>   
>> >
>> 
>>> > >   Thomas
>>>   
>> >
>> > Thanks for your responses. Now when I try
>> >
>> >  ret = { }
>> >  ret['a'] = 'b'
>> >  serialized = encoder.JSONEncoder().encode(ret)
>> >  print serialized
>> >
>> > then It works.
>> >
>> > But now I have another problem. I have a class "State":
>> >
>> > class State(models.Model):
>> > state = models.CharField(max_length = 30)
>> >
>> > def __unicode__(self):
>> > return self.state
>> >
>> > Throutht the admin page I create a state called "Slaskie".  
>> > Then the code :
>> >
>> > ret['b'] = State.objects.all()
>> > print 'ret: %' % ret
>> > try:
>> > serialized = encoder.JSONEncoder().encode(ret)
>> > except Exception, e:
>> > print 'exception: %s' % e
>> >
>> > returns the output:
>> >
>> > {'b': []}
>> > [] is not JSON serializable
>> >
>> > At the 
>> > pagehttp://docs.djangoproject.com/en/dev/topics/serialization/#id2there's
>> > written something about unicode and lazy translation. I tried to use
>> >
>> > le = LazyEncoder()   #lazy encoder is a given class from the
>> > link above
>> > serialized = le.encode(ret)
>> >
>> > and then the exception was:
>> > Circular reference detected
>> >
>> > when I tried
>> >
>> > le = LazyEncoder (ensure_ascii = False)
>> >
>> > the exception was the same:
>> > Circular reference detected
>> >
>> > What's going on with this lazy translation and unicode ? How can I
>> > serialize the data correctly ?
>> >
>> > Regards,
>> > Marek
>> 
> >
>
>   


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



Re: Inserting Into Cleaned_Data Inside a ModelForm

2009-03-06 Thread Waldemar Kornewald

On 6 Mrz., 14:13, Chris  wrote:
> I have a model that has a required attribute, but I want this
> attribute set to a calculated value based on the input from a form. So
> inside the save() method of my ModelForm class, I'm doing:
>
> self.cleaned_data['requiredKey'] = 123
> record = forms.ModelForm.save(self)

Just for reference:
http://groups.google.com/group/app-engine-patch/msg/a9ed56aaf326b17e

Bye,
Waldemar Kornewald
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Python Multiprocessing With Django

2009-03-06 Thread Jirka Vejrazka

> I have a management command that that starts up a few process to process a
> request: http://dpaste.com/7925/.

Hi, I was recently debugging similar issue and came to a conclusion
(which may be wrong of course :)  that multiprocessing and Django DB
connections don't play well together. I ended up closing Django DB
connection first thing in the new process. It'll recreate a new
connection when it needs one, but that one will have no references to
the connection used by the parent.

So, my Process.start() calls a function which starts with:
>>> from django.db import connection
>>> connection.close()

  This solved my problem.

   Cheers

 Jirka

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



Python Multiprocessing With Django

2009-03-06 Thread Vitaly Babiy
I have a management command that that starts up a few process to process a
request: http://dpaste.com/7925/.

But every so offen I get a exception say mysql went a way, but it didn't.
Process PoolWorker-3:
Traceback (most recent call last):
 File 
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/process.py",
line 236, in _bootstrap
   self.run()
 File
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/process.py",
line 93, in run
   self._target(*self._args, **self._kwargs)
 File
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/pool.py",
line 71, in worker
   put((job, i, result))
 File
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/queues.py",
line 353, in put
   return send(obj)
PicklingError: Can't pickle :
attribute lookup http_tracker.models.DoesNotExist failed
Traceback (most recent call last):
 File "/home/vbabiy/projects/git-projects/howsthedotcom/manage.py", line 11,
in 
   execute_manager(settings)
 File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 350, in execute_manager
   utility.execute()
 File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py",
line 295, in execute
   self.fetch_command(subcommand).run_from_argv(self.argv)
 File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 195, in run_from_argv
   self.execute(*args, **options.__dict__)
 File "/usr/lib/python2.5/site-packages/django/core/management/base.py",
line 222, in execute
   output = self.handle(*args, **options)
 File
"/home/vbabiy/projects/git-projects/howsthedotcom/tracker/management/commands/tracker.py",
line 37, in handle
   res = p.map(check_site, sites)
 File
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/pool.py",
line 148, in map
   return self.map_async(func, iterable, chunksize).get()
 File
"/usr/lib/python2.5/site-packages/multiprocessing-2.6.1.1-py2.5-linux-i686.egg/multiprocessing/pool.py",
line 422, in get
   raise self._value
_mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server
during query')

Any one got any idea why this is happening?

Vitaly Babiy

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



Re: translating app name ... again

2009-03-06 Thread patrickk

so, now here´s a little tutorial for translating app-names throughout
the admin-interface:

1. define the app-names: I´m currently using the __init__-file of my
blog-application. it looks like this:

from django.utils.translation import ugettext_lazy as _

_(u'auth')
_(u'configuration')
_(u'comments')
_(u'flatpages')
_(u'sites')
_(u'Auth')
_(u'Configuration')
_(u'Comments')
_(u'Flatpages')
_(u'Sites')
_(u'Auth-Verwaltung')
_(u'Configuration-Verwaltung')
_(u'Comments-Verwaltung')
_(u'Flatpages-Verwaltung')
_(u'Sites-Verwaltung')

2. translation (see django-tutorial). my translation looks like this
(don´t forget upper/lowercase as well as the translation for "app
index"):

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE
package.
# FIRST AUTHOR , YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-03-05 07:45+\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: __init__.py:3
msgid "auth"
msgstr "Benutzer & Gruppen"

#: __init__.py:4
msgid "configuration"
msgstr "Konfiguration"

#: __init__.py:5
msgid "comments"
msgstr "Kommentare"

#: __init__.py:6
msgid "flatpages"
msgstr "Statische Seiten"

#: __init__.py:7
msgid "sites"
msgstr "Domains"

#: __init__.py:3
msgid "Auth"
msgstr "Benutzer & Gruppen"

#: __init__.py:4
msgid "Configuration"
msgstr "Konfiguration"

#: __init__.py:5
msgid "Comments"
msgstr "Kommentare"

#: __init__.py:6
msgid "Flatpages"
msgstr "Statische Seiten"

#: __init__.py:7
msgid "Sites"
msgstr "Domains"

#: __init__.py:3
msgid "Auth-Verwaltung"
msgstr "Benutzer & Gruppen (Übersicht)"

#: __init__.py:4
msgid "Configuration-Verwaltung"
msgstr "Konfiguration (Übersicht)"

#: __init__.py:5
msgid "Comments-Verwaltung"
msgstr "Kommentare (Übersicht)"

#: __init__.py:6
msgid "Flatpages-Verwaltung"
msgstr "Statische Seiten (Übersicht)"

#: __init__.py:7
msgid "Sites-Verwaltung"
msgstr "Domains (Übersicht)"

3. change app-names in index.html /// on line 18 replace {% blocktrans
with app.name as name %}{{ name }}{% endblocktrans %} with {% trans
app.name %}

4. change breadcrumbs in change_list.html /// on line 25 replace
{{ app_label|capfirst }} with {% trans app_label %}

5. change breadcrumbs in change_form.html /// on line 28 replace
{ app_label|capfirst }} with {% trans app_label %}

6. change app-names in app_index.html /// on line 11 replace {%
blocktrans with app.name as name %}{{ name }}{% endblocktrans %} with
{% trans app.name %}

7. change title in base_site.html /// on line 69 replace {{ title }}
with {% trans title %}

a bit over-complicated, but it works ... be sure to have all possible
translations within your translation-file (django.po)

thanks to everybody for your help,
patrick



On 6 Mrz., 15:39, patrickk  wrote:
> you´re talking about the models name, not the applications name ...
>
> @nadya: with changing index.html the way you did it works for me as
> well.
> for changing the breadcrumbs (which obviously is a "must" if you
> change the app-names) you have to change change_list.html and
> change_form.html
>
> replace {{ app_label|capfirst }} with {% trans app_label %}
>
> in this case, you also have to provide the translations for app_label
> (lowercase).
>
> thanks,
> patrick
>
> On 6 Mrz., 14:56, Muslu Yüksektepe  wrote:
>
> > i dont understand..
> > do u wanna mean your app name?
> > if u wanna tell about your app name in admin panel
>
> > i think u can use
>
> > *USE_I18N = True
>
> > in settings.py*
>
> >  and
>
> >    * class Meta:
> >         verbose_name_plural = "Your App Name"
>
> > in models.py*
>
> > try it and write me answer please
>
> > 2009/3/4 patrickk 
>
> > > so far, it doesn´t seem possible to translate the app-names within the
> > > admin-interface, which results in a strange index-site with mixed
> > > languages.
>
> > > any updates on this issue? any ideas?
>
> > > thanks,
> > > patrick
>
> > --
> > Muslu YÜKSEKTEPE
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Figuring out what has changed at save()

2009-03-06 Thread Hank Sims

For what it's worth, I can imagine on way of doing this. I could use
signals to monkeypatch the instance at post_init, adding an attribute
called "post_init_status." Then I could compare this value with
"status" at post_save.

Please save me from doing something so ugly.

On Mar 6, 12:28 am, Rama Vadakattu  wrote:
> So you need to trigger an action the first time you save an object in
> to the database.
>
> --
>
> Class A:
>
>#self.id is None whenever a particular instance has not been saved
> into a database
>
>#override save method in the object as follows
>
>def save(self) :
>firstime = false
>
>if ~self.id :
>firsttime = true
>
>super.save()
>
>#this code only fires only when it is being saved for the first
> time.
>if firstime :
>   #Trigger an action whichevery you want.
>
> -
>
> Hope the above code helps you in resolving the problem.
>
> On Mar 6, 11:02 am, "hanks...@gmail.com"  wrote:
>
> > Sorry for the unwieldy title, but nothing else strikes me at the
> > moment.
>
> > I have a blog app -- a version of basic.blog, actually. There's a
> > field in the model called "status" with two options: "draft" and
> > "public."
>
> > What I want to do is trigger an action the first time (and /only/ the
> > first time) a particular instance is saved as "public."
>
> > So:
>
> > Write a post in the admin, save as draft --> No action
> > Edit the post some, save as draft again --> No action
> > Edit more, publish   --> Action triggered!
> > Edit again   --> No action.
>
> > How would I go about this? My thought is to override save(), but I
> > can't figure out how to inspect the instance at that point to
> > determine if the status attribute has changed since it was created. I
> > assume that this information must be in there somewhere, since it
> > seems like you'd need it to generate the SQL statement.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Figuring out what has changed at save()

2009-03-06 Thread Hank Sims

Rama:

Thanks, but that's no good. That would trigger the action whether or
not the post is saved as "draft."

Hank Sims

On Mar 6, 12:28 am, Rama Vadakattu  wrote:
> So you need to trigger an action the first time you save an object in
> to the database.
>
> --
>
> Class A:
>
>#self.id is None whenever a particular instance has not been saved
> into a database
>
>#override save method in the object as follows
>
>def save(self) :
>firstime = false
>
>if ~self.id :
>firsttime = true
>
>super.save()
>
>#this code only fires only when it is being saved for the first
> time.
>if firstime :
>   #Trigger an action whichevery you want.
>
> -
>
> Hope the above code helps you in resolving the problem.
>
> On Mar 6, 11:02 am, "hanks...@gmail.com"  wrote:
>
> > Sorry for the unwieldy title, but nothing else strikes me at the
> > moment.
>
> > I have a blog app -- a version of basic.blog, actually. There's a
> > field in the model called "status" with two options: "draft" and
> > "public."
>
> > What I want to do is trigger an action the first time (and /only/ the
> > first time) a particular instance is saved as "public."
>
> > So:
>
> > Write a post in the admin, save as draft --> No action
> > Edit the post some, save as draft again --> No action
> > Edit more, publish   --> Action triggered!
> > Edit again   --> No action.
>
> > How would I go about this? My thought is to override save(), but I
> > can't figure out how to inspect the instance at that point to
> > determine if the status attribute has changed since it was created. I
> > assume that this information must be in there somewhere, since it
> > seems like you'd need it to generate the SQL statement.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Django and Python Warnings

2009-03-06 Thread Brian Neal

I updated my working copy of Django after a long period and was
browsing the source and noticed it was taking advantage of the Python
warnings module. What is the best way to "see" such warnings when
doing development? Is it possible to configure Python or the Django
development server to display such warning messages?

For example, I was still using admin.site.root instead of include
(admin.site.urls) in my URLConf. I see the new code now issues a
PendingDeprecationWarning for this usage, however I didn't see it in
my development server window. I'm guessing I need to turn these on
somehow?

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-users@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
-~--~~~~--~~--~--~---



Re: translating app name ... again

2009-03-06 Thread patrickk

you´re talking about the models name, not the applications name ...

@nadya: with changing index.html the way you did it works for me as
well.
for changing the breadcrumbs (which obviously is a "must" if you
change the app-names) you have to change change_list.html and
change_form.html

replace {{ app_label|capfirst }} with {% trans app_label %}

in this case, you also have to provide the translations for app_label
(lowercase).

thanks,
patrick


On 6 Mrz., 14:56, Muslu Yüksektepe  wrote:
> i dont understand..
> do u wanna mean your app name?
> if u wanna tell about your app name in admin panel
>
> i think u can use
>
> *USE_I18N = True
>
> in settings.py*
>
>  and
>
>    * class Meta:
>         verbose_name_plural = "Your App Name"
>
> in models.py*
>
> try it and write me answer please
>
> 2009/3/4 patrickk 
>
>
>
> > so far, it doesn´t seem possible to translate the app-names within the
> > admin-interface, which results in a strange index-site with mixed
> > languages.
>
> > any updates on this issue? any ideas?
>
> > thanks,
> > patrick
>
> --
> Muslu YÜKSEKTEPE
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: translating app name ... again

2009-03-06 Thread Muslu Yüksektepe
i dont understand..
do u wanna mean your app name?
if u wanna tell about your app name in admin panel

i think u can use

*USE_I18N = True

in settings.py*

 and

   * class Meta:
verbose_name_plural = "Your App Name"

in models.py*


try it and write me answer please

2009/3/4 patrickk 

>
> so far, it doesn´t seem possible to translate the app-names within the
> admin-interface, which results in a strange index-site with mixed
> languages.
>
> any updates on this issue? any ideas?
>
> thanks,
> patrick
>
>
> >
>


-- 
Muslu YÜKSEKTEPE

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



Re: Creating a Symbolic Link using Windows

2009-03-06 Thread Sergio Durand

Hi,

Pay attention to the end of your trackeback :

snaggz03 escreveu:
> __init__.py", line 56, in cursor
> cursor = self._cursor(settings)
>   File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/
> base.py", line 262, in _cursor
> self.connection = Database.connect(**kwargs)
>   File "/var/lib/python-support/python2.5/MySQLdb/__init__.py", line
> 74 in Connect
> return Connection(*args, **Kwargs)
>   File"/var/lib/python-support/python2.5/MySQLdb/connections.py", line
> 170, in __init__
> super(Connection, self).__init__(*args, **kwargs2)
> _mysql_excptions.OperationalError:  (2005, "Unknown MySQL severhost
> 'myn...@virtualmachine.mydomain,com'  (1)")
>
> ***NOT actual severhost info

This traceback is very clear. "Unknown MySQL severhost" and  "***NOT 
actual severhost info"
Look into your settings.py files more specifically on database settings.

Tip:  use sqlite3 for learning django. It's very simple database easy to 
configure.

Sergio Durand

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



Re: translating app name ... again

2009-03-06 Thread Nadya Sevova

I put my translations in the django.po file and also changed a little
bit the admin's index.html template.

Replaced this:


{% blocktrans with app.name as name %}{{ name 
}}{%
endblocktrans %}



with this:
  {%
trans app.name %}


I can't figure out  why blocktranslate does not work in this case.
Tested it in a separate template and everything was ok.

Also cannot translate the app name in the admin's breadcrumbs.


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



Re: ImportError: Could not import settings '.settings'.

2009-03-06 Thread Muslu Yüksektepe
   46  PythonPath "['*/home/hutch/apps/wikinotes/*'] + sys.path"


try this code



2009/3/6 Ishwor Gurung 

> Hi
> I want to run this django app I wrote called wikinotes (its a modified
> version of note application to maintain user single user session [1])
> for simple note taking. While the wikinotes works absolutely correctly
> using "python manage.py runserver", it fails to work if i use it with
> Apache and mod_python.
>
> Now, I am trying to http://localhost:8000/wikinotes it does a redirect
> to http://localhost:8000/static/login.html which is desired behaviour
> everything works as desired (This is using django's own server fired
> using "python manage.py runserver").
>
> However, when I try to log into http://localhost/wikinotes using
> Apache, it redirects to http://localhost/static/login.html as desired.
> But after pressing "login" form button this time, it fails with the
> following traceback -
>
> 
> MOD_PYTHON ERROR
>
> ProcessId:  32469
> Interpreter:'localhost.localdomain'
>
> ServerName: 'localhost.localdomain'
> DocumentRoot:   '/var/www/'
>
> URI:'/wikinotes'
> Location:   '/wikinotes'
> Directory:  None
> Filename:   '/var/www/wikinotes'
> PathInfo:   ''
>
> Phase:  'PythonHandler'
> Handler:'django.core.handlers.modpython'
>
> Traceback (most recent call last):
>
>  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> 1537, in HandlerDispatch
>default=default_handler, arg=req, silent=hlist.silent)
>
>  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> 1229, in _process_target
>result = _execute_target(config, req, object, arg)
>
>  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> 1128, in _execute_target
>result = object(arg)
>
>  File
> "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py",
> line 228, in handler
>return ModPythonHandler()(req)
>
>  File
> "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py",
> line 191, in __call__
>self.load_middleware()
>
>  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py",
> line 31, in load_middleware
>for middleware_path in settings.MIDDLEWARE_CLASSES:
>
>  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line
> 28, in __getattr__
>self._import_settings()
>
>  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line
> 59, in _import_settings
>self._target = Settings(settings_module)
>
>  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line
> 94, in __init__
>raise ImportError, "Could not import settings '%s' (Is it on
> sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
>
> ImportError: Could not import settings 'wikinotes.settings' (Is it on
> sys.path? Does it have syntax errors?): No module named wikinotes.settings
>
> 
> Apache config -
> i...@debian:[~/apps/wikinotes] cat -n /etc/apache2/sites-available/default
> 1  
>40
>41  
>42  SetHandler python-program
>43  PythonHandler django.core.handlers.modpython
>44  SetEnv DJANGO_SETTINGS_MODULE wikinotes.settings
>45  PythonDebug On
>46  PythonPath "['/home/hutch/apps/wikinotes/wikinote'] +
> sys.path"
>47  
>48
>49  
> 
>
> i...@debian:[~/apps] ls
> wikinotes
>
> i...@debian:[~/apps/wikinotes] ls
> __init__.py  __init__.pyc  manage.py  media  settings.py  settings.pyc
>  static  urls.py  urls.pyc  wikinote  wikinotes.db
>
> i...@debian:[~/apps/wikinotes] cat -n urls.py
> 1  from django.conf.urls.defaults import *
> 2  from django.conf import settings
> 3
> 4  # Uncomment the next two lines to enable the admin:
> 5  from django.contrib import admin
> 6  admin.autodiscover()
> 7
> 8  urlpatterns = patterns('',
> 9  # Example:
>10  #(r'^wikinotes/', include('wikinotes.wikinote.urls')),
>11
>12  # Uncomment the admin/doc line below and add
> 'django.contrib.admindocs'
>13  # to INSTALLED_APPS to enable admin documentation:
>14  # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>15
>16  # Uncomment the next line to enable the admin:
>17  (r'^admin/(.*)', admin.site.root),
>18  (r'^media/(?P.*)$', 'django.views.static.serve',
> {'document_root': settings.MEDIA_ROOT }),
>19  (r'^static/(?P.*)$',
> 'django.views.static.serve',{'document_root': settings.STATIC_ROOT }),
>20  (r'^', include('wikinotes.wikinote.urls')),
>21  )
>
>
> i...@debian:[~/apps/wikinotes/wikinote] cat -n urls.py
> 1  # vim: ai ts=4 sts=4 et sw=4
> 2
> 3  from django.conf.urls.defaults import *
> 4  from wikinotes.wikinote.models import WikiNote
> 5  wikinotes = WikiNote.objects.all()
> 6
> 7  urlpatterns = patterns ('',
> 8  

Re: translating app name ... again

2009-03-06 Thread Nadya Sevova

I put my translations in the django.po file and also changed a little
bit the admin's index.html template.

Replaced this:


{% blocktrans with app.name as name %}{{ name 
}}{%
endblocktrans %}



with this:
  {%
trans app.name %}


I can't figure out  why blocktranslate does not work in this case.
Tested it in a separate template and everything was ok.

Also cannot translate the app name in the admin's breadcrumbs.


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



Re: Problems rendering HTML stored in database.

2009-03-06 Thread Muslu Yüksektepe
i think u can use markdown

{{ html_text|markup }}
or
{{ html_text|textile }}

try this



2009/3/6 nils 

>
> Im running django-1.0.2-final with the django.contrib.admin in my
> application.
> It's a blog-like application so i implemented tiny-mce (wysiwyg-
> editor) in the admin interface.
> It saves/deletes/updates as supposed, but the view+template does not
> render the HTML-tags, the HTML-tags renders as plain text.
>
> Any one know why?
>
>
> >
>


-- 
Muslu YÜKSEKTEPE

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



Re: Problems rendering HTML stored in database.

2009-03-06 Thread hugoto

Yeah, the default behaviour in django templates is to escape html
code, so if you render something like hello, the template
will convert it to h1 ... etc.
This is for prevent the script inyections in forms. So if you want to
show the raw html as is in the database you have no escape the text
with the safe filter:

{{ html_text|safe }}

On 6 mar, 07:15, nils  wrote:
> Im running django-1.0.2-final with the django.contrib.admin in my
> application.
> It's a blog-like application so i implemented tiny-mce (wysiwyg-
> editor) in the admin interface.
> It saves/deletes/updates as supposed, but the view+template does not
> render the HTML-tags, the HTML-tags renders as plain text.
>
> Any one know why?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: ModelForm/clean_

2009-03-06 Thread gregor kling

Daniel Roseman wrote:
> On Mar 6, 10:37 am, gregor kling 
> wrote:
>> Hello List,
>>
>> I have a form inheriting from ModelForm.
>> class C(ModelForm):
>>  
>>
>>  class Meta:
>>  model = SomeModel
>>
>>  def clean_somefield:
>>  enhanced checks
>>
>> Now my problem is how to access session data (request.session)
>> from within the clean method.
>> Does anyone have a clue how to this.
>>
>> gfk
> 
> Override the form's __init__ method to accept the request as a keyword
> parameter, and stash it in an instance attribute.
> 
> class MyForm(forms.ModelForm):
> def __init__(self, *args, **kwargs):
> self.request = kwargs.pop('request')
> super(MyForm, self).__init__(*args, **kwargs)
> 
> def clean_somefield(self):
> .. do something with self.request...
> 
> form = MyForm(request.POST, request=request, instance=myinstance)
Thanks Daniel. That works like a charm.
gfk
> --
> DR.
> > 


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



Inserting Into Cleaned_Data Inside a ModelForm

2009-03-06 Thread Chris

I have a model that has a required attribute, but I want this
attribute set to a calculated value based on the input from a form. So
inside the save() method of my ModelForm class, I'm doing:

self.cleaned_data['requiredKey'] = 123
record = forms.ModelForm.save(self)

However, this raises the error "ValueError: The Record could not be
created (Property requiredKey is required)".

Is cleaned_data read-only? How would I modify the data used when
creating the model? I realize I could probably set requiredKey as a
form field, and then set it in clean_requiredKey(), but I don't want
the field included in the actual form (not even as a hidden field).

Any help is appreciated.

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



Problems rendering HTML stored in database.

2009-03-06 Thread nils

Im running django-1.0.2-final with the django.contrib.admin in my
application.
It's a blog-like application so i implemented tiny-mce (wysiwyg-
editor) in the admin interface.
It saves/deletes/updates as supposed, but the view+template does not
render the HTML-tags, the HTML-tags renders as plain text.

Any one know why?


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



Re: Django Resource Usage

2009-03-06 Thread stout . elias

Hi,

I've used the past two years django 0.96 with fastcgi in a shared
server, an average website with products, image processing, forms, etc
will take from 10mb to 15mb.

David

On Mar 6, 11:46 am, Paulo  wrote:
> My main concern is about django in standby. Does it take too much
> resources? Not too much customers will be using it so i guess it's not
> a problem.
>
> On 5 mar, 23:08, Paulo  wrote:
>
> > Hi
>
> > I want to install Django on my webserver, but i would like to know
> > from you if django has an intense resource usage (memory, cpu) or it's
> > not a concern?
>
> > I'm planning to install it on some shared web servers and need to know
> > this information, because i don't want to slow down performance on the
> > server.
>
> > 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-users@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
-~--~~~~--~~--~--~---



Re: Django Certifications

2009-03-06 Thread Peter Herndon

In short, no.If you are looking to create one, feel free, there's
no competition.  There's also been no discernible demand, from what
I've seen.

On 3/6/09, Praveen  wrote:
>
> Is there any Django certification as others like SCJP, MCSE, CCNA and
> more on?
> >
>

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



Re: ModelForm/clean_

2009-03-06 Thread Daniel Roseman

On Mar 6, 10:37 am, gregor kling 
wrote:
> Hello List,
>
> I have a form inheriting from ModelForm.
> class C(ModelForm):
>      
>
>      class Meta:
>          model = SomeModel
>
>      def clean_somefield:
>          enhanced checks
>
> Now my problem is how to access session data (request.session)
> from within the clean method.
> Does anyone have a clue how to this.
>
> gfk

Override the form's __init__ method to accept the request as a keyword
parameter, and stash it in an instance attribute.

class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super(MyForm, self).__init__(*args, **kwargs)

def clean_somefield(self):
.. do something with self.request...

form = MyForm(request.POST, request=request, instance=myinstance)
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django Resource Usage

2009-03-06 Thread Paulo

My main concern is about django in standby. Does it take too much
resources? Not too much customers will be using it so i guess it's not
a problem.

On 5 mar, 23:08, Paulo  wrote:
> Hi
>
> I want to install Django on my webserver, but i would like to know
> from you if django has an intense resource usage (memory, cpu) or it's
> not a concern?
>
> I'm planning to install it on some shared web servers and need to know
> this information, because i don't want to slow down performance on the
> server.
>
> 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-users@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
-~--~~~~--~~--~--~---



Re: Django Resource Usage

2009-03-06 Thread Paulo

Well, this leads me to an unknown path. Where i can find more
information about how to install it and tweak it?

On 6 mar, 00:04, Graham Dumpleton  wrote:
> On Mar 6, 1:24 pm, Malcolm Tredinnick 
> wrote:
>
>
>
> > On Thu, 2009-03-05 at 18:08 -0800, Paulo wrote:
> > > Hi
>
> > > I want to install Django on my webserver, but i would like to know
> > > from you if django has an intense resource usage (memory, cpu) or it's
> > > not a concern?
>
> > As always, it depends on what you're doing. There simply *cannot* be any
> > general answer to that question. That being said, typing "resource
> > usage" into the search box on the django-users Google Groups page turns
> > up a bunch of previous messages on this topic. Searching the archives
> > will certainly give you some ideas of things to consider when
> > benchmarking.
>
> > The solution is always to profile and benchmark on your development
> > systems before deploying.
>
> It also depends on how you intend to deploy Django. If you try and run
> it under mod_python or mod_wsgi embedded mode in Apache with prefork
> MPM, then it can take huge amounts of memory. Even with worker MPM you
> have to be careful and consider changing the default Apache MPM
> settings as they default to be values more appropriate for static file
> serving and PHP. Better deployment scenarios are mod_wsgi daemon mode
> or fastcgi solutions with number of processes/threads used strictly
> controlled.
>
> So, how do you intend deploying it?
>
> Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Django Application's Response Time

2009-03-06 Thread Rama Vadakattu

if you really want to measure the page response time  (amount of time
that a page has taken to download on your local computer)

1) you can use firebug (popular) : it shows all the request and
reponse...

2) AOL's web based test tool  :  webpagetest.org

3) IBM's page detailer (desktop verion)  : 
http://alphaworks.ibm.com/tech/pagedetailer

For speeding up your site i suggest you to take a  look at the
performance best practices at
 1) http://developer.yahoo.com/performance/rules.html
and a excellent video talk given steve sounders which gives various
insights  of improving websites performance.
   http://www.youtube.com/watch?v=BTHvs3V8DBA

The video tells that we can drastically reduce a page reponse time by
tuning the front-end (which accounts 90% of page's performanace time)
like (number http requests,javescript locations,css sprites etc)
instead of back-end which accouts only 10% of entire page response
time.
























On Mar 6, 2:36 pm, Harish  wrote:
> Hi All,
>
> I want to calculate the response time of web application  designed in
> django..
> Basically I do not have any idea how to proceed with this
>
> Any suggestions or idea on this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: Forms: custom clean for DateField

2009-03-06 Thread MarcoS

 Sorry, i've posted without finishing the message :)

So, if I call clean(self), Django give me this exception for the
following line:

super(forms.DateField, self).clean()

Exception Type: TypeError
Exception Value:
super(type, obj): obj must be an instance or subtype of type

To solve it I tried to replace

super(forms.DateField, self).clean()

with:

super(DateField, self.fields['firstDate']).clean(self)

but I think isn't correct and however the super class doesn't raises
any
exception for input that isn't in a date format.

Please, give me any ideas



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



ModelForm/clean_

2009-03-06 Thread gregor kling

Hello List,

I have a form inheriting from ModelForm.
class C(ModelForm):
 

 class Meta:
 model = SomeModel

 def clean_somefield:
 enhanced checks

Now my problem is how to access session data (request.session)
from within the clean method.
Does anyone have a clue how to this.


gfk

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



Django Application's Response Time

2009-03-06 Thread Harish

Hi All,

I want to calculate the response time of web application  designed in
django..
Basically I do not have any idea how to proceed with this

Any suggestions or idea on this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Re: ImportError: Could not import settings '.settings'.

2009-03-06 Thread Ishwor Gurung
Hi

Ishwor Gurung wrote:
> Hi

[  ]

Another follow up (and hopefully last one for the night). The problem
was with my mod_python, view and urlconf configs -

I changed mod_python directives from what was in the previous to:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE wikinotes.settings
PythonDebug On
PythonPath "['/home/hutch/apps/', '/var/www'] + sys.path"


and did a bunch of path fixes to view and urlconf (shouldn't this be
uneeded? because the reasoning is that every time a web developer
creates a project, they shouldn't have to muck around with either
views/urlconf so as to reflect apache settings right?

However, this is not urgent per se but if someone knows a "better way"
to fix up my view and urlconf so it is independent of apache, it'd be
really nice if they could point me to a documentation.

Done. Thanks for reading my wild rants. Umphh! :D

Cheers,
Ishwor.




smime.p7s
Description: S/MIME Cryptographic Signature


template include and for loop speed

2009-03-06 Thread Thierry

the following use case

{% for item in items %}
 {% with item.score as score %}
  {% include rating_small %}
 {% endwith %}
{% endfor %}

Using an include tag is very slow compared to pasting the included
template here.
My total template processing time goes up from 0.1 to 0.4 seconds.
Why is an include tag so much heavier on the template system?

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



Re: Optimizing my ORM query

2009-03-06 Thread Sebastian Bauer
W dniu 06.03.2009 01:24, Malcolm Tredinnick pisze:
> On Thu, 2009-03-05 at 18:48 -0500, Jeff Gentry wrote:
>
>> Suppose I have three models (in pseudocode):
>>
>> class Foo:
>> asdf = models.CharField()
>>
>> class Blah:
>> qwerty = models.CharField()
>>
>> class Bob:
>> foo = models.ForeignKey(Foo)
>> blah = models.ForeignKey(Blah)
>>
>> Given a Foo and a list of Blahs (where the length of the list might be
>> very small (0-10) but also could be quite large (100k+)), what would be
>> the most efficient way of extracting the appropriate Bob objects?  I'd
>> prefer the results to preserve the order of the Blahs, but failing that
>> I'd at least need a way of looking up which Blah a Bob instance pairs with
>> w/o nailing the DB a gajillion times.
>>
>> Right now I'm working with
>> Bob.objects.filter(foo=myFoo).filter(blah__in=myBlahs)
>>  
>
> Seems like the best (and obvious) way to me.
>
>
>> But even this doesn't really meet my preserving order requirement
>>  
>
> Yes it does. As written, your models have no ordering requirements. That
> complete lack of constraint is preserved perfectly. :-)
>
>
>>   as I'm
>> assuming the "in" filter doesn't guarantee order preservation anyways
>> (although I could order the Blahs by ID and then do an
>> order_by('blah_id') I would imagine).
>>  
>
> Precisely. If you want ordering, you have to specify it. The database is
> in no way obliged to return rows even in the order they are stored on
> disk, so if you're relying on that, you are making an error.
>
> Regards,
> Malcolm
>

if you returning myBlahs in other query i think you can do somethink 
like this:

blah_subquery="blah_id IN (%s)" %  
Blah.objects.values("id").filter(qwerty__icontains='somethink').query
Bob.objects.filter(foo=myFoo).extra(where=blah_subquery)

this is taken from 
http://blog.yumbunny.com/2008/12/django-subqueries-in-where-clause.html

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



  1   2   >