Re: What's the most scalable Django deployment out there currently?

2009-03-24 Thread Alex Gaynor
On Wed, Mar 25, 2009 at 1:06 AM, Graham Dumpleton <
graham.dumple...@gmail.com> wrote:

>
>
>
> On Mar 25, 3:45 pm, Alex Gaynor  wrote:
> > On Wed, Mar 25, 2009 at 12:43 AM, Adam V.  wrote:
> >
> > > Curse (http://www.curse.com/) manages to stay up on WoW patch day, so
> > > that's a pretty good sign.
> >
> > Curse is no longer running on Django(it's ASP.net now I think), no idea
> if
> > that was a technical decision or not.
>
> If it using ASP.net, maybe that is why none of their addresses respond
> to me from where I am. :-)
>
> Curse was using mod_python:
>
>  http://www.davidcramer.net/curse/44/what-powers-curse.html
>
> David Cramer though has since switched to mod_wsgi and has expressed
> the opinion that mod_wsgi works a lot better.
>
> Important think though is not so much the hosting mechanism but how
> well you optimise the performance of your application and database.
>
> Graham
>
>
>
> >
>
David also did a good talk on scaling Django(based on his experiences at
curse) at DjangoCon, the video is on youtube.

Alex

-- 
"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: What's the most scalable Django deployment out there currently?

2009-03-24 Thread Graham Dumpleton



On Mar 25, 3:45 pm, Alex Gaynor  wrote:
> On Wed, Mar 25, 2009 at 12:43 AM, Adam V.  wrote:
>
> > Curse (http://www.curse.com/) manages to stay up on WoW patch day, so
> > that's a pretty good sign.
>
> Curse is no longer running on Django(it's ASP.net now I think), no idea if
> that was a technical decision or not.

If it using ASP.net, maybe that is why none of their addresses respond
to me from where I am. :-)

Curse was using mod_python:

  http://www.davidcramer.net/curse/44/what-powers-curse.html

David Cramer though has since switched to mod_wsgi and has expressed
the opinion that mod_wsgi works a lot better.

Important think though is not so much the hosting mechanism but how
well you optimise the performance of your application and database.

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: What's the most scalable Django deployment out there currently?

2009-03-24 Thread Alex Gaynor
On Wed, Mar 25, 2009 at 12:43 AM, Adam V.  wrote:

>
> Curse (http://www.curse.com/) manages to stay up on WoW patch day, so
> that's a pretty good sign.
>
> >
>
Curse is no longer running on Django(it's ASP.net now I think), no idea if
that was a technical decision or not.

Alex

-- 
"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: What's the most scalable Django deployment out there currently?

2009-03-24 Thread Adam V.

Curse (http://www.curse.com/) manages to stay up on WoW patch day, so
that's a pretty good sign.

--~--~-~--~~~---~--~~
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: What's the most scalable Django deployment out there currently?

2009-03-24 Thread ldm616

I guess I'm asking if there's any inherent reason to *not* use Django
for a website that you hope/anticipate will have many simultaneous
users and high levels of database reads/updates. And, related, what's
the most "extreme" Django deployment currently out there.

And on the database side, what database do folks recommend for the
more extreme apps. Can mysql go all the way or are there limitations
there too?

On Mar 24, 9:34 pm, Alex Gaynor  wrote:
> On Wed, Mar 25, 2009 at 12:32 AM, ldm999  wrote:
>
> > Is there any reason why Django couldn't be used to create a website
> > that gets Facebook-like traffic?
>
> Not really, at that point it's mostly scaling your DB(since web nodes are
> comparatively easy).  Django doesn't have a public API for mulitple
> databases so it could be harder, but there is both private APIs and external
> tools like PgPool.
>
> However, what's the real question you're trying to answer?  100% of websites
> don't get traffic that approaches facebook.
>
> Alex
>
> --
> "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: What's the most scalable Django deployment out there currently?

2009-03-24 Thread Alex Gaynor
On Wed, Mar 25, 2009 at 12:32 AM, ldm999  wrote:

>
> Is there any reason why Django couldn't be used to create a website
> that gets Facebook-like traffic?
> >
>
Not really, at that point it's mostly scaling your DB(since web nodes are
comparatively easy).  Django doesn't have a public API for mulitple
databases so it could be harder, but there is both private APIs and external
tools like PgPool.

However, what's the real question you're trying to answer?  100% of websites
don't get traffic that approaches facebook.

Alex

-- 
"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
-~--~~~~--~~--~--~---



What's the most scalable Django deployment out there currently?

2009-03-24 Thread ldm999

Is there any reason why Django couldn't be used to create a website
that gets Facebook-like traffic?
--~--~-~--~~~---~--~~
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: Bug report: Model.get(pk=None)

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 20:40 -0400, Karen Tracey wrote:
[...]
> 
> But the decision was made to not add this overhead to the start of
> every connection. If you read the last paragraph you'll note it wasn't
> an emphatic "no, never shall we do this" type of decision but I don't
> know that anything has come to light to change the decision here,
> other than a couple of people have noticed the oddness.  

I think it's pretty emphatic these days. I wasn't rushing to judgement
at the time, but nothing has happened in the interim to convince me that
sort of change would be a good idea. We consistently reflect the
database server's behaviour throughout Django. This is another case of
that. If people choose MySQL, they get to experience all the
consequences of that choice, both good and bad.

I'd be strongly against changing it now. Adding extra overhead to every
single connection to work around something that 99.9% of normal code
won't do anyway and can easily be avoided would be irresponsible. If
somebody wants to pass in pk=None and doesn't want the MySQL behaviour
to occur they can use a server that doesn't do that or configure it off
(and remember to do that every single time they use a different MySQL
install). In practice, though, simply not sending through pk=None is the
easy solution (that's how Django works internally for example).

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: Call function on server start

2009-03-24 Thread Graham Dumpleton



On Mar 25, 11:53 am, Malcolm Tredinnick 
wrote:
> On Tue, 2009-03-24 at 14:59 -0700, JGAllen23 wrote:
> > Is there any way to call a function on server start?  I have some
> > maintenance stuff that I'd like to run on server start (both manage.py
> > runserver and apache reload).  Is there any way to do that?
>
> No, because the requirement doesn't make sense. Processes are stopped
> and started *frequently* during the running of a website. A web server
> like Apache kills child processes after a certain number of requests (to
> control memory usage, etc) and starts new ones. You'll see thousands of
> stops and starts over the course of a week.
>
> You shouldn't use something designed for a "shared nothing" setup, such
> as Django, to try and influence things like that, since the lifecycles
> are completely mismatched.

With Apache, also need to take into consideration that it is a
multiprocess web server. Thus, even if you use features of mod_python
or mod_wsgi to perform some action when a worker process first starts,
that same action might be triggered in multiple processes at the same
time. You therefore have to deal with contention issues if they are
trying to operate on the same thing.

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: Call function on server start

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 14:59 -0700, JGAllen23 wrote:
> Is there any way to call a function on server start?  I have some
> maintenance stuff that I'd like to run on server start (both manage.py
> runserver and apache reload).  Is there any way to do that?

No, because the requirement doesn't make sense. Processes are stopped
and started *frequently* during the running of a website. A web server
like Apache kills child processes after a certain number of requests (to
control memory usage, etc) and starts new ones. You'll see thousands of
stops and starts over the course of a week.

You shouldn't use something designed for a "shared nothing" setup, such
as Django, to try and influence things like that, since the lifecycles
are completely mismatched.

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: Bug report: Model.get(pk=None)

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 16:50 -0400, Michael Glassford wrote:
> Alex Gaynor wrote:
> > 
> > I'm almost positive the MySQL CLI operates differently for the purposes 
> > of this query.  The reason the queries do different things in .96 is 
> > that in .96 that query becomes id = NULL rather than id IS NULL, which 
> > MySQL handles differently.
> > 
> 
> Well, that fits the facts that I know. However, from a Django point of 
> view it's pretty unexpected. Would you agree that it should be 
> considered a Django bug, and should be fixed?

It's not a bug. You are receiving exactly what the database offers up
for that query. Yes, the behaviour would be considered a show-stopping
bug for any normal database. MySQL considers it a feature. We're not
going to interfere with that, since (a) people are free to choose their
own database server and (b) some people might actually agree with the
MySQL developers and be relying on that behaviour.

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: Bug report: Model.get(pk=None)

2009-03-24 Thread Karen Tracey
On Tue, Mar 24, 2009 at 8:15 PM, Michael Glassford wrote:

> Django can be patched to do this automatically. There may be a better
> way to do it, but I've figured out that in db/backends/mysql/base.py,
> inside the DatabaseWrapper._cursor function, adding the line
> "cursor.execute('SET sql_auto_is_null=0;')" immediately after the
> "cursor = CursorWrapper(self.connection.cursor())" line will do it.
> Should I submit a patch or is this just something that's not going to be
> fixed?
>

That is the workaround/fix identified when this behavior was first
discovered:

http://groups.google.com/group/django-developers/browse_thread/thread/d4180b8addf5e970

But the decision was made to not add this overhead to the start of every
connection. If you read the last paragraph you'll note it wasn't an emphatic
"no, never shall we do this" type of decision but I don't know that anything
has come to light to change the decision here, other than a couple of people
have noticed the oddness.  The other I recall recently is here:

http://code.djangoproject.com/ticket/10339

which was closed wontfix.

Personally, I don't think adding the set_auto_is_null=0 to every connection
is worth it.  Adding a note to the doc somewhere might be useful, though I'm
not sure how many would actually read and find that explanation when they
stumble over this behavior.

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: Static Content and Google App Engine

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 08:56 -0700, tgorham3 wrote:
> Django documentation clearly disapproves of storing static content in
> a database. 

Well, no, but it acknowledges that a filesystem is usually a better
solution for that type of operation, as it's optimised for storing large
files (SQL databases are not).

>  Google App Engine treats blobs in the db as the norm.
> 
> Does Big Table change the rules or is it still preferable to store
> static content in the file system and let a server do the heavy
> lifting.

Big Table is entirely different from a relational database, on so many
levels. If you're using Google App Engine, you're running in a very
different environment anyway (since Google gives a type of server and
it's not something you're configuring yourself).

The problem with your question is that almost any answer will be correct
for some particular set of circumstances. If you have a particular
problem in mind that you're trying to solve and one approach or the
other isn't working for you for some reason, try an alternate approach.
If you're wondering about the performance characteristics of GAE, ask on
their mailing list(s), since the experts over there will know about
things.

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: Bug report: Model.get(pk=None)

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 8:15 PM, Michael Glassford wrote:

>
> Alex Gaynor wrote:
> >
> >
> > On Tue, Mar 24, 2009 at 2:51 PM, Michael Glassford wrote:
> >
> >
> > Alex Gaynor wrote:
> >  >
> >  >
> >  > On Tue, Mar 24, 2009 at 2:39 PM, Michael Glassford wrote:
> >
> > [snip model definition, etc.]
> >
> >  > When I run the tests under Django 0.96.3, I get the expected
> > exception:
> >  > "DoesNotExist: ModelA matching query does not exist."
> >  >
> >  > However, under Django 1.0, 1.0.1, 1.0.2, and the current
> > trunk (revision
> >  > 10162 at the time when I tested this), the
> > "ModelA.objects.get(pk=None)"
> >  > statement unexpectedly returns the object created by the
> >  > "ModelA.objects.create()" on the previous line.
> >  >
> >  >
> >  > Mike
> >  >
> >  >
> >  >
> >  >
> >  > Under MySQL doing a query of the form WHERE primary_key IS NULL
> > returns
> >  > the last created row.
> >  >
> >  > Alex
> >
> >
> >
> > Not here:
> >
> > mysql> show create table myapp_modela;
> >
> +--+--+
> > | Table| Create Table
> >
> >   |
> >
> +--+--+
> > | myapp_modela | CREATE TABLE `myapp_modela` (
> >   `id` int(11) NOT NULL auto_increment,
> >   PRIMARY KEY  (`id`)
> > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
> >
> +--+--+
> > 1 row in set (0.00 sec)
> >
> > mysql> insert into myapp_modela values (1);
> > Query OK, 1 row affected (0.00 sec)
> >
> > mysql> select * from myapp_modela where id is NULL;
> > Empty set (0.00 sec)
> >
> >
> >
> > Also, that doesn't explain why Django 0.96 does what I expected.
> >
> >
> >
> > I'm almost positive the MySQL CLI operates differently for the purposes
> > of this query.  The reason the queries do different things in .96 is
> > that in .96 that query becomes id = NULL rather than id IS NULL, which
> > MySQL handles differently.
>
>
> After more research, it turns out that my example doesn't display the
> problem because it isn't testing for the right thing. The actual
> behavior that MySQL implements is to return the last row inserted using
> an auto-increment id (which the above did not, since I supplied the id).
> Changing the example accordingly:
>
> mysql> insert into myapp_modela values();
> Query OK, 1 row affected (0.00 sec)
>
> mysql> select * from myapp_modela where id is null;
> ++
> | id |
> ++
> |  6 |
> ++
> 1 row in set (0.00 sec)
>
>
>
>
> However, this behavior can be turned off:
>
> mysql> set sql_auto_is_null = 0; #Turn off using session variable
> Query OK, 0 rows affected (0.00 sec)
>
> mysql> insert into myapp_modela values();
> Query OK, 1 row affected (0.00 sec)
>
> mysql> select * from myapp_modela where id is null;
> Empty set (0.00 sec)
>
>
>
>
> Django can be patched to do this automatically. There may be a better
> way to do it, but I've figured out that in db/backends/mysql/base.py,
> inside the DatabaseWrapper._cursor function, adding the line
> "cursor.execute('SET sql_auto_is_null=0;')" immediately after the
> "cursor = CursorWrapper(self.connection.cursor())" line will do it.
> Should I submit a patch or is this just something that's not going to be
> fixed?
>
>
>
> Mike
>
> >
>
I believe that was discussed and decided against when the original
discussion occured on django-developers, you'd have to find the original
thread to be certain though.

Alex

-- 
"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: Languages problem

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 07:33 -0700, alexarsh wrote:
> Hi,
> 
> No, I don't have any errors. I just get my title empty.

So is the data not being stored in the database? Use psql and have a
look at the table directly to see what's there.

Django quite happily handles non-ASCII text in the admin
(http://www.flickr.com/photos/malcolmtredinnick/494663115/ ), so I agree
with Muslu: reduce your example to something simpler, particularly by
removing the custom save() handling in your test case for now. Once you
have it working in the simple case, that's the right time to add back
the missing pieces.

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: Templating language Include path dilemma

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 05:36 -0700, Colm wrote:
[..]
> Assuming foo_app/template/template1 looks like this :
> 
> {% include "path1/temtlate2" %}
> 
> If template2 wants to include template3 should it do this :
> 
>{ % include "../path2/template3" %}
> 
> OR this :
> 
>   {% include "path2/template3" %}
> 
> From what you have said I'm gathering it is the latter.  Is that
> correct?

Yes, it's the latter case. The second template has absolutely no
knowledge of being include by the first.

> 
> Also, is the former idiom (the use of "..") meaningful at all when
> evaluating includes and if so what does it mean?   If it is meaningful
> at all does it mean "relative to the templates directory"? i.e. if I
> had :
> 
>templates/foo
>otherstuff/blah
> 
> .. could I include "blah" by saying {% include "../otherstuff/blah"
> %}.  Or does that not make sense?

The paths are resolved as relative paths against all the roots of the
template hierarchy. However, the resolution is constrainted to lie
*within* all those roots. So ../foo doesn't make sense unless you have
both "first/" and "first/second/" in the template hierarchy and
"first/foo" exists (since then it resolves as relative to first/second
and lands inside /first/ to find /first/foo).

People really shouldn't use paths like that, though. It's pretty
incomprehensible to others reading the templates.

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: Bug report: Model.get(pk=None)

2009-03-24 Thread Michael Glassford

Alex Gaynor wrote:
> 
> 
> On Tue, Mar 24, 2009 at 2:51 PM, Michael Glassford wrote:
> 
> 
> Alex Gaynor wrote:
>  >
>  >
>  > On Tue, Mar 24, 2009 at 2:39 PM, Michael Glassford wrote:
> 
> [snip model definition, etc.]
> 
>  > When I run the tests under Django 0.96.3, I get the expected
> exception:
>  > "DoesNotExist: ModelA matching query does not exist."
>  >
>  > However, under Django 1.0, 1.0.1, 1.0.2, and the current
> trunk (revision
>  > 10162 at the time when I tested this), the
> "ModelA.objects.get(pk=None)"
>  > statement unexpectedly returns the object created by the
>  > "ModelA.objects.create()" on the previous line.
>  >
>  >
>  > Mike
>  >
>  >
>  >
>  >
>  > Under MySQL doing a query of the form WHERE primary_key IS NULL
> returns
>  > the last created row.
>  >
>  > Alex
> 
> 
> 
> Not here:
> 
> mysql> show create table myapp_modela;
> 
> +--+--+
> | Table| Create Table
>
>   |
> 
> +--+--+
> | myapp_modela | CREATE TABLE `myapp_modela` (
>   `id` int(11) NOT NULL auto_increment,
>   PRIMARY KEY  (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
> 
> +--+--+
> 1 row in set (0.00 sec)
> 
> mysql> insert into myapp_modela values (1);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> select * from myapp_modela where id is NULL;
> Empty set (0.00 sec)
> 
> 
> 
> Also, that doesn't explain why Django 0.96 does what I expected.
> 
> 
> 
> I'm almost positive the MySQL CLI operates differently for the purposes 
> of this query.  The reason the queries do different things in .96 is 
> that in .96 that query becomes id = NULL rather than id IS NULL, which 
> MySQL handles differently.


After more research, it turns out that my example doesn't display the 
problem because it isn't testing for the right thing. The actual 
behavior that MySQL implements is to return the last row inserted using 
an auto-increment id (which the above did not, since I supplied the id). 
Changing the example accordingly:

mysql> insert into myapp_modela values();
Query OK, 1 row affected (0.00 sec)

mysql> select * from myapp_modela where id is null;
++
| id |
++
|  6 |
++
1 row in set (0.00 sec)




However, this behavior can be turned off:

mysql> set sql_auto_is_null = 0; #Turn off using session variable
Query OK, 0 rows affected (0.00 sec)

mysql> insert into myapp_modela values();
Query OK, 1 row affected (0.00 sec)

mysql> select * from myapp_modela where id is null;
Empty set (0.00 sec)




Django can be patched to do this automatically. There may be a better 
way to do it, but I've figured out that in db/backends/mysql/base.py, 
inside the DatabaseWrapper._cursor function, adding the line 
"cursor.execute('SET sql_auto_is_null=0;')" immediately after the 
"cursor = CursorWrapper(self.connection.cursor())" line will do it. 
Should I submit a patch or is this just something that's not going to be 
fixed?



Mike

--~--~-~--~~~---~--~~
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: OT: svn and '$Id$'

2009-03-24 Thread Alan

I got a solution.

I undid what I did in ~/.subversion/config
Forget about Id, and used just  "$Date$" in my *.py, then
find . -name "*.py" -exec svn propset svn:keywords "Date" {} \;
commit it and it worked.

Cheers,
Alan

On Mar 24, 5:34 pm, Alan  wrote:
> Hi guys, tanks for your help but I am definitely doning something
> wrong because I don't get what I want.
>
> So, I am trying this:
>
> I have this line in my *.py file:
>
> repositoryId = '$Id $' + '$Revision$' + '$Date$'
>
> I did:
> find . -name "*.py" -exec svn propset svn:keywords "Date" {} \;
> find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;
>
> and I also have in my ~/.subversion/config:
> enable-auto-props = yes
> *.py = svn:keywords=Id;svn:eol-style=native
>
> So, when I commit my file, I was expecting to see something change in
> " repositoryId = '$Id $' + '$Revision$' + '$Date$' ", like I would see
> if I were using CVS.
>
> I am using Eclipse btw, but svn ci is not doing better either.
>
> Many thanks,
> Alan
>
> On Mar 24, 5:25 pm, David Lindquist  wrote:
>
>
>
> > On Mar 24, 2009, at 10:09 AM, Alan wrote:
>
> > > Hi there,
>
> > > It's a bit off topic but I guess appropriate anyway.
>
> > > So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> > > when I commit my files via svn.
>
> > > But I googled and I still couldn't make it work. Can somebody tell  
> > > to make it work? I would like to get at least date and time when  
> > > the files are committed ( svn on googlecode) in the file itself.
>
> > > Many thanks in advance.
>
> > > Alan
>
> > > --
> > > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> > > Department of Biochemistry, University of Cambridge.
> > > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> > > >>http://www.bio.cam.ac.uk/~awd28<<
>
> > Rather, that should be:
>
> > find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;
--~--~-~--~~~---~--~~
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 won't my form validate?

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 6:10 PM, Theme Park Photo, LLC wrote:

>
> Actually, no. The docs have this example which will fail
>
> # Create a form to edit an existing Article.
> >>> a = Article.objects.get(pk=1)
> >>> f = ArticleForm(instance=a)
> >>> f.save()
>
>
>
> On Mar 24, 12:34 pm, David Zhou  wrote:
> > It builds up on the things mentioned in the documentation for normal
> > forms.  Also, the documentation for ModelForm's save instance has
> > pretty explicit examples of creating form instances:
> >
> > http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
> >
> > -- dz
> >
> > On Tue, Mar 24, 2009 at 3:21 PM, Theme Park Photo, LLC
> >
> >  wrote:
> >
> > > Error fields were all empty. I checked methods non_field_errors and
> > > _get_errors; _errors was None.
> >
> > > But Alex Gaynor was right! When I added the form "POST" data in, the
> > > form validated. I assumed that creating a ModelForm from an existing
> > > instance would give it valid data, but that's not the case. (Though
> > > the Django Documentation doesn't say this:
> > >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/)
> >
> > > On Mar 24, 12:15 pm, David Zhou  wrote:
> > >> If it's not valid, then something likely threw a validation error.
> > >> What does the error say?
> >
> > >> -- dz
> >
> > >> On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
> >
> > >>  wrote:
> >
> > >> > It has data! It was created from an existing instance...and all the
> > >> > fields have values
> >
> > >> > 'body': u'hello there', 'allow_comments':
> > >> >1, 'author': 10L, 'tease': u'hello there > >> > p>',
> > >> >'publish': datetime.datetime(2009, 3, 23, 15,
> > >> > 3,
> > >> >36), 'score': -93L, 'categories': [1L],
> > >> > 'title':
> > >> >u'Hello', 'slug': u'hello-0', 'tags':
> > >> > u'hello'}
> >
> > >> > On Mar 24, 12:06 pm, Alex Gaynor  wrote:
> > >> >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC <
> swir...@gmail.com>wrote:
> >
> > >> >> > Im trying to get code to edit an existing record in a table
> working.
> > >> >> > For some reason, form.is_valid is returning false (and I can't
> save it
> > >> >> > because there's no cleaned data). Even reduced to this (below)
> where
> > >> >> > I'm simply getting an existing "Post" object, creating a
> ModelForm,
> > >> >> > and validating it, fails!
> >
> > >> >> > Any suggestions?
> >
> > >> >> >post = Post.objects.get(id=postId)
> > >> >> >form = PostForm(instance=post)
> > >> >> >if form.is_valid(): # All validation rules pass
> > >> >> >form.save()
> > >> >> >else:
> > >> >> >   # at this point, non_field_errors and _get_errors
> > >> >> > return null. _errors is defined as none(), yet form.is_valid
> > >> >> >   # is returning false
> >
> > >> >> A form without data is never considered valid.  You probably want
> your
> > >> >> workflow to be more like:
> >
> > >> >> obj = Model.objects.get()
> > >> >> if request.method == 'POST':
> > >> >> form = Form(request.POST, isntance=obj)
> > >> >> if form.is_valid():
> > >> >>form.save()
> > >> >> else:
> > >> >>  form = Form(instance=obj)
> > >> >> return render_to_response()
> >
> > >> >> --
> > >> >> "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
> >
>
Please file a ticket about that.

Alex

-- 
"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: Why won't my form validate?

2009-03-24 Thread Theme Park Photo, LLC

Actually, no. The docs have this example which will fail

# Create a form to edit an existing Article.
>>> a = Article.objects.get(pk=1)
>>> f = ArticleForm(instance=a)
>>> f.save()



On Mar 24, 12:34 pm, David Zhou  wrote:
> It builds up on the things mentioned in the documentation for normal
> forms.  Also, the documentation for ModelForm's save instance has
> pretty explicit examples of creating form instances:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-sav...
>
> -- dz
>
> On Tue, Mar 24, 2009 at 3:21 PM, Theme Park Photo, LLC
>
>  wrote:
>
> > Error fields were all empty. I checked methods non_field_errors and
> > _get_errors; _errors was None.
>
> > But Alex Gaynor was right! When I added the form "POST" data in, the
> > form validated. I assumed that creating a ModelForm from an existing
> > instance would give it valid data, but that's not the case. (Though
> > the Django Documentation doesn't say this:
> >http://docs.djangoproject.com/en/dev/topics/forms/modelforms/)
>
> > On Mar 24, 12:15 pm, David Zhou  wrote:
> >> If it's not valid, then something likely threw a validation error.
> >> What does the error say?
>
> >> -- dz
>
> >> On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
>
> >>  wrote:
>
> >> > It has data! It was created from an existing instance...and all the
> >> > fields have values
>
> >> > 'body': u'hello there', 'allow_comments':
> >> >                        1, 'author': 10L, 'tease': u'hello there >> > p>',
> >> >                        'publish': datetime.datetime(2009, 3, 23, 15,
> >> > 3,
> >> >                        36), 'score': -93L, 'categories': [1L],
> >> > 'title':
> >> >                        u'Hello', 'slug': u'hello-0', 'tags':
> >> > u'hello'}
>
> >> > On Mar 24, 12:06 pm, Alex Gaynor  wrote:
> >> >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC 
> >> >> wrote:
>
> >> >> > Im trying to get code to edit an existing record in a table working.
> >> >> > For some reason, form.is_valid is returning false (and I can't save it
> >> >> > because there's no cleaned data). Even reduced to this (below) where
> >> >> > I'm simply getting an existing "Post" object, creating a ModelForm,
> >> >> > and validating it, fails!
>
> >> >> > Any suggestions?
>
> >> >> >        post = Post.objects.get(id=postId)
> >> >> >        form = PostForm(instance=post)
> >> >> >        if form.is_valid(): # All validation rules pass
> >> >> >                        form.save()
> >> >> >        else:
> >> >> >               # at this point, non_field_errors and _get_errors
> >> >> > return null. _errors is defined as none(), yet form.is_valid
> >> >> >               # is returning false
>
> >> >> A form without data is never considered valid.  You probably want your
> >> >> workflow to be more like:
>
> >> >> obj = Model.objects.get()
> >> >> if request.method == 'POST':
> >> >>     form = Form(request.POST, isntance=obj)
> >> >>     if form.is_valid():
> >> >>        form.save()
> >> >> else:
> >> >>      form = Form(instance=obj)
> >> >> return render_to_response()
>
> >> >> --
> >> >> "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
-~--~~~~--~~--~--~---



Call function on server start

2009-03-24 Thread JGAllen23

Is there any way to call a function on server start?  I have some
maintenance stuff that I'd like to run on server start (both manage.py
runserver and apache reload).  Is there any way to do that?
--~--~-~--~~~---~--~~
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: Admin Model Search issue.

2009-03-24 Thread Ayaz Ahmed Khan


On 24-Mar-09, at 9:28 PM, Bobby Roberts wrote:

> When I try to search on anything at all, the screen just blinks and
> returns all of the records.  This same syntax works perfectly on
> another model.  There's no error but the search function in the
> /admin is not working.  Any ideas what it could be?

Do you mind sharing the class definition for this model? Is any of the
fields in the search_fields by any chance a ForeignKey or such?
Despite the fact that Django stipulates that search fields be some
form of text fields, I was able to reproduce what you described by
including a ForeignKey in search_fields without using the lookup API
follow notation---I tested on 0.97-pre-SVN-unknown.

-- 
Ayaz Ahmed Khan

An evil mind is a great comfort.


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



Error when posting a comment

2009-03-24 Thread Tonu Mikk

I posted this on djangothreadedcomments list some days ago, but did not 
get a response.  Perhaps django users can help me out?


Hello, I am attempting to get threaded comments to work on a shared
bookmarking application.  It seems that I am almost there, but when I
post the comment, I get the following error: "This XML file does not
appear to have any style information associated with it. The document
tree is shown below."

I copied the relevant parts of the application to dpaste.com including
models, views and template:  http://dpaste.com/16206/ .  Perhaps
someone may be able to spot a problem in my application.

Thank you!

Tonu




--~--~-~--~~~---~--~~
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: Bug report: Model.get(pk=None)

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 4:50 PM, Michael Glassford wrote:

>
> Alex Gaynor wrote:
> >
> > I'm almost positive the MySQL CLI operates differently for the purposes
> > of this query.  The reason the queries do different things in .96 is
> > that in .96 that query becomes id = NULL rather than id IS NULL, which
> > MySQL handles differently.
> >
>
> Well, that fits the facts that I know. However, from a Django point of
> view it's pretty unexpected. Would you agree that it should be
> considered a Django bug, and should be fixed?
>
> Mike
>
> >
>
No, there was a thread during the queryset-refactor where Malcolm brought
this up and the decision was if MySQL wants to do strange things we're
wasting our time trying to stop it.

Alex

-- 
"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: Bug report: Model.get(pk=None)

2009-03-24 Thread Michael Glassford

Alex Gaynor wrote:
> 
> I'm almost positive the MySQL CLI operates differently for the purposes 
> of this query.  The reason the queries do different things in .96 is 
> that in .96 that query becomes id = NULL rather than id IS NULL, which 
> MySQL handles differently.
> 

Well, that fits the facts that I know. However, from a Django point of 
view it's pretty unexpected. Would you agree that it should be 
considered a Django bug, and should be fixed?

Mike

--~--~-~--~~~---~--~~
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: Join unrelated models

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 4:26 PM, Konstantin S  wrote:

>
>
>
> On Mar 24, 11:13 pm, Alex Gaynor  wrote:
> > On Tue, Mar 24, 2009 at 4:05 PM, Konstantin S 
> wrote:
> >
> > > Hello!
> >
> > > I have two unrelated models that have one common field.
> >
> > > class Media(models.Model):
> > >title = models.CharField(max_length=500)
> > >...
> >
> > > class Link(models.Model):
> > >title = models.CharField(max_length=500)
> > >...
> >
> > > Now I want to select those objects from the Media model that do not
> > > exist in the Link model if we compare them only by 'title' field. In
> > > raw SQL it looks like this:
> >
> > > select * from Media left join Link on Media.title=Link.title where
> > > Link.title is null;
> >
> > > Is it possible to make the same thing by Django ORM only ?
> >
> > So to be clear you want all items from Media for which there isn't a link
> > with that title, in the ORM that would look like:
> >
> > Media.objects.exclude(title__in=Link.objects.values('title'))
> >
>
> Yes, but I want to be sure that it uses JOIN syntax.
>
> >
>
It's not possible to do that using the ORM, you'll need to use some raw sql.

Alex

-- 
"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: Join unrelated models

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 4:15 PM, Paulo Köch  wrote:

>
> Does that generate a join or a not in? This is very relevant for
> performance.
>
> Cheers,
> Paulo Köch
>
>
>
> On Tue, Mar 24, 2009 at 20:13, Alex Gaynor  wrote:
> >
> >
> > On Tue, Mar 24, 2009 at 4:05 PM, Konstantin S 
> wrote:
> >>
> >> Hello!
> >>
> >> I have two unrelated models that have one common field.
> >>
> >> class Media(models.Model):
> >>title = models.CharField(max_length=500)
> >>...
> >>
> >> class Link(models.Model):
> >>title = models.CharField(max_length=500)
> >>...
> >>
> >> Now I want to select those objects from the Media model that do not
> >> exist in the Link model if we compare them only by 'title' field. In
> >> raw SQL it looks like this:
> >>
> >> select * from Media left join Link on Media.title=Link.title where
> >> Link.title is null;
> >>
> >> Is it possible to make the same thing by Django ORM only ?
> >>
> >>
> >
> > So to be clear you want all items from Media for which there isn't a link
> > with that title, in the ORM that would look like:
> >
> > Media.objects.exclude(title__in=Link.objects.values('title'))
> >
> > Alex
> >
> > --
> > "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
> >
> > >
> >
>
> >
>
No, it's done using a subquery.

Alex

-- 
"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: Join unrelated models

2009-03-24 Thread Paulo Köch

Does that generate a join or a not in? This is very relevant for performance.

Cheers,
Paulo Köch



On Tue, Mar 24, 2009 at 20:13, Alex Gaynor  wrote:
>
>
> On Tue, Mar 24, 2009 at 4:05 PM, Konstantin S  wrote:
>>
>> Hello!
>>
>> I have two unrelated models that have one common field.
>>
>> class Media(models.Model):
>>    title = models.CharField(max_length=500)
>>    ...
>>
>> class Link(models.Model):
>>    title = models.CharField(max_length=500)
>>    ...
>>
>> Now I want to select those objects from the Media model that do not
>> exist in the Link model if we compare them only by 'title' field. In
>> raw SQL it looks like this:
>>
>> select * from Media left join Link on Media.title=Link.title where
>> Link.title is null;
>>
>> Is it possible to make the same thing by Django ORM only ?
>>
>>
>
> So to be clear you want all items from Media for which there isn't a link
> with that title, in the ORM that would look like:
>
> Media.objects.exclude(title__in=Link.objects.values('title'))
>
> Alex
>
> --
> "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: Join unrelated models

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 4:05 PM, Konstantin S  wrote:

>
> Hello!
>
> I have two unrelated models that have one common field.
>
> class Media(models.Model):
>title = models.CharField(max_length=500)
>...
>
> class Link(models.Model):
>title = models.CharField(max_length=500)
>...
>
> Now I want to select those objects from the Media model that do not
> exist in the Link model if we compare them only by 'title' field. In
> raw SQL it looks like this:
>
> select * from Media left join Link on Media.title=Link.title where
> Link.title is null;
>
> Is it possible to make the same thing by Django ORM only ?
>
> >
>
So to be clear you want all items from Media for which there isn't a link
with that title, in the ORM that would look like:

Media.objects.exclude(title__in=Link.objects.values('title'))

Alex

-- 
"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
-~--~~~~--~~--~--~---



Join unrelated models

2009-03-24 Thread Konstantin S

Hello!

I have two unrelated models that have one common field.

class Media(models.Model):
title = models.CharField(max_length=500)
...

class Link(models.Model):
title = models.CharField(max_length=500)
...

Now I want to select those objects from the Media model that do not
exist in the Link model if we compare them only by 'title' field. In
raw SQL it looks like this:

select * from Media left join Link on Media.title=Link.title where
Link.title is null;

Is it possible to make the same thing by Django ORM only ?

--~--~-~--~~~---~--~~
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 won't my form validate?

2009-03-24 Thread David Zhou

It builds up on the things mentioned in the documentation for normal
forms.  Also, the documentation for ModelForm's save instance has
pretty explicit examples of creating form instances:

http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

-- dz



On Tue, Mar 24, 2009 at 3:21 PM, Theme Park Photo, LLC
 wrote:
>
> Error fields were all empty. I checked methods non_field_errors and
> _get_errors; _errors was None.
>
> But Alex Gaynor was right! When I added the form "POST" data in, the
> form validated. I assumed that creating a ModelForm from an existing
> instance would give it valid data, but that's not the case. (Though
> the Django Documentation doesn't say this:
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ )
>
>
> On Mar 24, 12:15 pm, David Zhou  wrote:
>> If it's not valid, then something likely threw a validation error.
>> What does the error say?
>>
>> -- dz
>>
>> On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
>>
>>  wrote:
>>
>> > It has data! It was created from an existing instance...and all the
>> > fields have values
>>
>> > 'body': u'hello there', 'allow_comments':
>> >                        1, 'author': 10L, 'tease': u'hello there> > p>',
>> >                        'publish': datetime.datetime(2009, 3, 23, 15,
>> > 3,
>> >                        36), 'score': -93L, 'categories': [1L],
>> > 'title':
>> >                        u'Hello', 'slug': u'hello-0', 'tags':
>> > u'hello'}
>>
>> > On Mar 24, 12:06 pm, Alex Gaynor  wrote:
>> >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC 
>> >> wrote:
>>
>> >> > Im trying to get code to edit an existing record in a table working.
>> >> > For some reason, form.is_valid is returning false (and I can't save it
>> >> > because there's no cleaned data). Even reduced to this (below) where
>> >> > I'm simply getting an existing "Post" object, creating a ModelForm,
>> >> > and validating it, fails!
>>
>> >> > Any suggestions?
>>
>> >> >        post = Post.objects.get(id=postId)
>> >> >        form = PostForm(instance=post)
>> >> >        if form.is_valid(): # All validation rules pass
>> >> >                        form.save()
>> >> >        else:
>> >> >               # at this point, non_field_errors and _get_errors
>> >> > return null. _errors is defined as none(), yet form.is_valid
>> >> >               # is returning false
>>
>> >> A form without data is never considered valid.  You probably want your
>> >> workflow to be more like:
>>
>> >> obj = Model.objects.get()
>> >> if request.method == 'POST':
>> >>     form = Form(request.POST, isntance=obj)
>> >>     if form.is_valid():
>> >>        form.save()
>> >> else:
>> >>      form = Form(instance=obj)
>> >> return render_to_response()
>>
>> >> --
>> >> "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: Why won't my form validate?

2009-03-24 Thread Theme Park Photo, LLC

Error fields were all empty. I checked methods non_field_errors and
_get_errors; _errors was None.

But Alex Gaynor was right! When I added the form "POST" data in, the
form validated. I assumed that creating a ModelForm from an existing
instance would give it valid data, but that's not the case. (Though
the Django Documentation doesn't say this:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ )


On Mar 24, 12:15 pm, David Zhou  wrote:
> If it's not valid, then something likely threw a validation error.
> What does the error say?
>
> -- dz
>
> On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
>
>  wrote:
>
> > It has data! It was created from an existing instance...and all the
> > fields have values
>
> > 'body': u'hello there', 'allow_comments':
> >                        1, 'author': 10L, 'tease': u'hello there > p>',
> >                        'publish': datetime.datetime(2009, 3, 23, 15,
> > 3,
> >                        36), 'score': -93L, 'categories': [1L],
> > 'title':
> >                        u'Hello', 'slug': u'hello-0', 'tags':
> > u'hello'}
>
> > On Mar 24, 12:06 pm, Alex Gaynor  wrote:
> >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC 
> >> wrote:
>
> >> > Im trying to get code to edit an existing record in a table working.
> >> > For some reason, form.is_valid is returning false (and I can't save it
> >> > because there's no cleaned data). Even reduced to this (below) where
> >> > I'm simply getting an existing "Post" object, creating a ModelForm,
> >> > and validating it, fails!
>
> >> > Any suggestions?
>
> >> >        post = Post.objects.get(id=postId)
> >> >        form = PostForm(instance=post)
> >> >        if form.is_valid(): # All validation rules pass
> >> >                        form.save()
> >> >        else:
> >> >               # at this point, non_field_errors and _get_errors
> >> > return null. _errors is defined as none(), yet form.is_valid
> >> >               # is returning false
>
> >> A form without data is never considered valid.  You probably want your
> >> workflow to be more like:
>
> >> obj = Model.objects.get()
> >> if request.method == 'POST':
> >>     form = Form(request.POST, isntance=obj)
> >>     if form.is_valid():
> >>        form.save()
> >> else:
> >>      form = Form(instance=obj)
> >> return render_to_response()
>
> >> --
> >> "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: Why won't my form validate?

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 3:15 PM, David Zhou  wrote:

>
> If it's not valid, then something likely threw a validation error.
> What does the error say?
>
> -- dz
>
>
>
> On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
>  wrote:
> >
> > It has data! It was created from an existing instance...and all the
> > fields have values
> >
> > 'body': u'hello there', 'allow_comments':
> >1, 'author': 10L, 'tease': u'hello there > p>',
> >'publish': datetime.datetime(2009, 3, 23, 15,
> > 3,
> >36), 'score': -93L, 'categories': [1L],
> > 'title':
> >u'Hello', 'slug': u'hello-0', 'tags':
> > u'hello'}
> >
> >
> > On Mar 24, 12:06 pm, Alex Gaynor  wrote:
> >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC <
> swir...@gmail.com>wrote:
> >>
> >>
> >>
> >>
> >>
> >> > Im trying to get code to edit an existing record in a table working.
> >> > For some reason, form.is_valid is returning false (and I can't save it
> >> > because there's no cleaned data). Even reduced to this (below) where
> >> > I'm simply getting an existing "Post" object, creating a ModelForm,
> >> > and validating it, fails!
> >>
> >> > Any suggestions?
> >>
> >> >post = Post.objects.get(id=postId)
> >> >form = PostForm(instance=post)
> >> >if form.is_valid(): # All validation rules pass
> >> >form.save()
> >> >else:
> >> >   # at this point, non_field_errors and _get_errors
> >> > return null. _errors is defined as none(), yet form.is_valid
> >> >   # is returning false
> >>
> >> A form without data is never considered valid.  You probably want your
> >> workflow to be more like:
> >>
> >> obj = Model.objects.get()
> >> if request.method == 'POST':
> >> form = Form(request.POST, isntance=obj)
> >> if form.is_valid():
> >>form.save()
> >> else:
> >>  form = Form(instance=obj)
> >> return render_to_response()
> >>
> >> --
> >> "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
> > >
> >
>
> >
>
Yes, but the form isn't bound, only bound forms can be valid as documented:
http://code.djangoproject.com/browser/django/trunk/django/forms/forms.py#L115

Alex

-- 
"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: More DJango Tagging Oracle Issues

2009-03-24 Thread Brandon Taylor

I have confirmed that it also works as expected with cx_Oracle-5.0.1

Woohoo

On Mar 24, 2:14 pm, Brandon Taylor  wrote:
> After much digging, I was able to find the problem. In fields.py in
> django-tagging, the tags are pulled from cache when they are saved,
> rather than going back to the database.
>
> The problem I was seeing wasn't that tags werent' being applied to
> objects, or added to the database, but the input field was NOT
> reflecting the changes to the tags. The cache was not being set with
> the new values.
>
> So, I found a ticket on the tagging 
> site:http://code.google.com/p/django-tagging/issues/detail?id=28=1=c...
>
> Which has a patch, but that doesn't work for the svn checkout of
> django-tagging. I changed the _post_init method to:
>
> #fields.py
> def contribute_to_class(self, cls, name):
>         super(TagField, self).contribute_to_class(cls, name)
>
>         # Make this object the descriptor for field access.
>         setattr(cls, self.name, self)
>
>         # Save tags back to the database post-save
>         signals.post_save.connect(self._save, cls, True)
>         signals.post_init.connect(self._post_init, cls, True) #wire it
> up here
>
> def _post_init(self, **kwargs):
>         instance = kwargs['instance']
>         if instance._get_pk_val() is None:
>             self._set_instance_tag_cache(instance, '')
>         else:
>             self._set_instance_tag_cache(instance, edit_string_for_tags
> (Tag.objects.get_for_object(instance)))
>             #this re-sets the tags from the database
>
> This caused some interesting behavior on the form field. Instead of
> tags being separated by commas, and multi-word tags being enclosed in
> quotes, everything was just separated by a space. This causes tags to
> be improperly assigned on the next save. So, I changed the
> edit_string_for_tags method to:
>
> def edit_string_for_tags(tags):
>     names = []
>     for tag in tags:
>         name = tag.name
>         if u' ' in name:
>             names.append('"%s"' % name)
>             continue
>         names.append(name)
>
>     return ', '.join(names)
>
> Now tags are properly formatted in my tags text field, and tags are
> properly assigned to objects. This also does not break compatibility
> with other DB types for me. Last step will be to replace my
> cx_Oracle-4.4.1 driver with the latest 5.0.1, and see if it still
> works.
>
> Hope this helps someone out!
>
> Cheers,
> Brandon
>
> On Mar 23, 5:40 pm, Brandon Taylor  wrote:
>
> > Hi Ian,
>
> > I'm not that familiar with Oracle, so I have no idea if the problems
> > I'm experiencing are related in some way to permissions, etc, but I
> > have been reassured by my Oracle person that my user has full
> > permissions on my schema.
>
> > That being said, the TagField() will show up in admin when specifying:
>
> > from tagging.fields import TagField
>
> > class MyModel(models.Model):
> >     tags = TagField()
>
> > When I create a new record, any tags that I have entered will be saved
> > to the tagging tables and associated to the record. However, when I
> > update the record, and add tags that aren't already present, or remove
> > all of the tags, no changes to the record will occur. All of the tags
> > that were there when I created the record are still there, but no new
> > tags, and no tags removed.
>
> > If I take the *exact* same model code, and switch my database to
> > SQLite or MySQL, I have no issues. I can only deduce that it's
> > something either wrong with my Oracle permissions, or with cx_Oracle
> > itself. I have wiped out my tables, re-validated, re-sync'd. Quadruple-
> > checked my code. And still the same problem. But yes, at least I can
> > add tags.
>
> > Perplexed,
> > Brandon
>
> > On Mar 23, 4:31 pm, Ian Kelly  wrote:
>
> > > On Mar 23, 1:52 pm, Brandon Taylor  wrote:
>
> > > > Hi Everyone,
>
> > > > Is anyone having issues with Django Tagging (svn) not updating tags on
> > > > an existing model? I'm running cx_Oracle-4.4.1 - thanks to (Ian Kelly)
> > > > and Django Trunk.
>
> > > Hmm.  I tried running the same model you posted before with Python 2.6
> > > and cx_Oracle 5.0.1, and I can't see that it makes any difference; it
> > > still works for me.  Glad you got it (at least partially) working,
> > > though.
>
> > > > I can add tags when a model instance is created, but update/delete is
> > > > not working.
>
> > > Can you be more specific?  It seems to be working for me.
>
> > > Regards,
> > > Ian
--~--~-~--~~~---~--~~
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 won't my form validate?

2009-03-24 Thread David Zhou

If it's not valid, then something likely threw a validation error.
What does the error say?

-- dz



On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC
 wrote:
>
> It has data! It was created from an existing instance...and all the
> fields have values
>
> 'body': u'hello there', 'allow_comments':
>                        1, 'author': 10L, 'tease': u'hello there p>',
>                        'publish': datetime.datetime(2009, 3, 23, 15,
> 3,
>                        36), 'score': -93L, 'categories': [1L],
> 'title':
>                        u'Hello', 'slug': u'hello-0', 'tags':
> u'hello'}
>
>
> On Mar 24, 12:06 pm, Alex Gaynor  wrote:
>> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC 
>> wrote:
>>
>>
>>
>>
>>
>> > Im trying to get code to edit an existing record in a table working.
>> > For some reason, form.is_valid is returning false (and I can't save it
>> > because there's no cleaned data). Even reduced to this (below) where
>> > I'm simply getting an existing "Post" object, creating a ModelForm,
>> > and validating it, fails!
>>
>> > Any suggestions?
>>
>> >        post = Post.objects.get(id=postId)
>> >        form = PostForm(instance=post)
>> >        if form.is_valid(): # All validation rules pass
>> >                        form.save()
>> >        else:
>> >               # at this point, non_field_errors and _get_errors
>> > return null. _errors is defined as none(), yet form.is_valid
>> >               # is returning false
>>
>> A form without data is never considered valid.  You probably want your
>> workflow to be more like:
>>
>> obj = Model.objects.get()
>> if request.method == 'POST':
>>     form = Form(request.POST, isntance=obj)
>>     if form.is_valid():
>>        form.save()
>> else:
>>      form = Form(instance=obj)
>> return render_to_response()
>>
>> --
>> "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: More DJango Tagging Oracle Issues

2009-03-24 Thread Brandon Taylor

After much digging, I was able to find the problem. In fields.py in
django-tagging, the tags are pulled from cache when they are saved,
rather than going back to the database.

The problem I was seeing wasn't that tags werent' being applied to
objects, or added to the database, but the input field was NOT
reflecting the changes to the tags. The cache was not being set with
the new values.

So, I found a ticket on the tagging site:
http://code.google.com/p/django-tagging/issues/detail?id=28=1=cache

Which has a patch, but that doesn't work for the svn checkout of
django-tagging. I changed the _post_init method to:

#fields.py
def contribute_to_class(self, cls, name):
super(TagField, self).contribute_to_class(cls, name)

# Make this object the descriptor for field access.
setattr(cls, self.name, self)

# Save tags back to the database post-save
signals.post_save.connect(self._save, cls, True)
signals.post_init.connect(self._post_init, cls, True) #wire it
up here

def _post_init(self, **kwargs):
instance = kwargs['instance']
if instance._get_pk_val() is None:
self._set_instance_tag_cache(instance, '')
else:
self._set_instance_tag_cache(instance, edit_string_for_tags
(Tag.objects.get_for_object(instance)))
#this re-sets the tags from the database


This caused some interesting behavior on the form field. Instead of
tags being separated by commas, and multi-word tags being enclosed in
quotes, everything was just separated by a space. This causes tags to
be improperly assigned on the next save. So, I changed the
edit_string_for_tags method to:

def edit_string_for_tags(tags):
names = []
for tag in tags:
name = tag.name
if u' ' in name:
names.append('"%s"' % name)
continue
names.append(name)

return ', '.join(names)


Now tags are properly formatted in my tags text field, and tags are
properly assigned to objects. This also does not break compatibility
with other DB types for me. Last step will be to replace my
cx_Oracle-4.4.1 driver with the latest 5.0.1, and see if it still
works.

Hope this helps someone out!

Cheers,
Brandon

On Mar 23, 5:40 pm, Brandon Taylor  wrote:
> Hi Ian,
>
> I'm not that familiar with Oracle, so I have no idea if the problems
> I'm experiencing are related in some way to permissions, etc, but I
> have been reassured by my Oracle person that my user has full
> permissions on my schema.
>
> That being said, the TagField() will show up in admin when specifying:
>
> from tagging.fields import TagField
>
> class MyModel(models.Model):
>     tags = TagField()
>
> When I create a new record, any tags that I have entered will be saved
> to the tagging tables and associated to the record. However, when I
> update the record, and add tags that aren't already present, or remove
> all of the tags, no changes to the record will occur. All of the tags
> that were there when I created the record are still there, but no new
> tags, and no tags removed.
>
> If I take the *exact* same model code, and switch my database to
> SQLite or MySQL, I have no issues. I can only deduce that it's
> something either wrong with my Oracle permissions, or with cx_Oracle
> itself. I have wiped out my tables, re-validated, re-sync'd. Quadruple-
> checked my code. And still the same problem. But yes, at least I can
> add tags.
>
> Perplexed,
> Brandon
>
> On Mar 23, 4:31 pm, Ian Kelly  wrote:
>
> > On Mar 23, 1:52 pm, Brandon Taylor  wrote:
>
> > > Hi Everyone,
>
> > > Is anyone having issues with Django Tagging (svn) not updating tags on
> > > an existing model? I'm running cx_Oracle-4.4.1 - thanks to (Ian Kelly)
> > > and Django Trunk.
>
> > Hmm.  I tried running the same model you posted before with Python 2.6
> > and cx_Oracle 5.0.1, and I can't see that it makes any difference; it
> > still works for me.  Glad you got it (at least partially) working,
> > though.
>
> > > I can add tags when a model instance is created, but update/delete is
> > > not working.
>
> > Can you be more specific?  It seems to be working for me.
>
> > Regards,
> > Ian
--~--~-~--~~~---~--~~
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 won't my form validate?

2009-03-24 Thread Theme Park Photo, LLC

It has data! It was created from an existing instance...and all the
fields have values

'body': u'hello there', 'allow_comments':
1, 'author': 10L, 'tease': u'hello there',
'publish': datetime.datetime(2009, 3, 23, 15,
3,
36), 'score': -93L, 'categories': [1L],
'title':
u'Hello', 'slug': u'hello-0', 'tags':
u'hello'}


On Mar 24, 12:06 pm, Alex Gaynor  wrote:
> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC 
> wrote:
>
>
>
>
>
> > Im trying to get code to edit an existing record in a table working.
> > For some reason, form.is_valid is returning false (and I can't save it
> > because there's no cleaned data). Even reduced to this (below) where
> > I'm simply getting an existing "Post" object, creating a ModelForm,
> > and validating it, fails!
>
> > Any suggestions?
>
> >        post = Post.objects.get(id=postId)
> >        form = PostForm(instance=post)
> >        if form.is_valid(): # All validation rules pass
> >                        form.save()
> >        else:
> >               # at this point, non_field_errors and _get_errors
> > return null. _errors is defined as none(), yet form.is_valid
> >               # is returning false
>
> A form without data is never considered valid.  You probably want your
> workflow to be more like:
>
> obj = Model.objects.get()
> if request.method == 'POST':
>     form = Form(request.POST, isntance=obj)
>     if form.is_valid():
>        form.save()
> else:
>      form = Form(instance=obj)
> return render_to_response()
>
> --
> "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: Why won't my form validate?

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC wrote:

>
> Im trying to get code to edit an existing record in a table working.
> For some reason, form.is_valid is returning false (and I can't save it
> because there's no cleaned data). Even reduced to this (below) where
> I'm simply getting an existing "Post" object, creating a ModelForm,
> and validating it, fails!
>
> Any suggestions?
>
>
>post = Post.objects.get(id=postId)
>form = PostForm(instance=post)
>if form.is_valid(): # All validation rules pass
>form.save()
>else:
>   # at this point, non_field_errors and _get_errors
> return null. _errors is defined as none(), yet form.is_valid
>   # is returning false
>
> >
>
A form without data is never considered valid.  You probably want your
workflow to be more like:

obj = Model.objects.get()
if request.method == 'POST':
form = Form(request.POST, isntance=obj)
if form.is_valid():
   form.save()
else:
 form = Form(instance=obj)
return render_to_response()


-- 
"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
-~--~~~~--~~--~--~---



Why won't my form validate?

2009-03-24 Thread Theme Park Photo, LLC

Im trying to get code to edit an existing record in a table working.
For some reason, form.is_valid is returning false (and I can't save it
because there's no cleaned data). Even reduced to this (below) where
I'm simply getting an existing "Post" object, creating a ModelForm,
and validating it, fails!

Any suggestions?


post = Post.objects.get(id=postId)
form = PostForm(instance=post)
if form.is_valid(): # All validation rules pass
form.save()
else:
   # at this point, non_field_errors and _get_errors
return null. _errors is defined as none(), yet form.is_valid
   # is returning false

--~--~-~--~~~---~--~~
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: Bug report: Model.get(pk=None)

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 2:51 PM, Michael Glassford wrote:

>
> Alex Gaynor wrote:
> >
> >
> > On Tue, Mar 24, 2009 at 2:39 PM, Michael Glassford  > > wrote:
>
> [snip model definition, etc.]
>
> > When I run the tests under Django 0.96.3, I get the expected
> exception:
> > "DoesNotExist: ModelA matching query does not exist."
> >
> > However, under Django 1.0, 1.0.1, 1.0.2, and the current trunk
> (revision
> > 10162 at the time when I tested this), the
> "ModelA.objects.get(pk=None)"
> > statement unexpectedly returns the object created by the
> > "ModelA.objects.create()" on the previous line.
> >
> >
> > Mike
> >
> >
> >
> >
> > Under MySQL doing a query of the form WHERE primary_key IS NULL returns
> > the last created row.
> >
> > Alex
>
>
>
> Not here:
>
> mysql> show create table myapp_modela;
>
> +--+--+
> | Table| Create Table
>   |
>
> +--+--+
> | myapp_modela | CREATE TABLE `myapp_modela` (
>   `id` int(11) NOT NULL auto_increment,
>   PRIMARY KEY  (`id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
>
> +--+--+
> 1 row in set (0.00 sec)
>
> mysql> insert into myapp_modela values (1);
> Query OK, 1 row affected (0.00 sec)
>
> mysql> select * from myapp_modela where id is NULL;
> Empty set (0.00 sec)
>
>
>
>
>
> Also, that doesn't explain why Django 0.96 does what I expected.
>
>
>
>
> Mike
>
> >
>
I'm almost positive the MySQL CLI operates differently for the purposes of
this query.  The reason the queries do different things in .96 is that in
.96 that query becomes id = NULL rather than id IS NULL, which MySQL handles
differently.

-- 
"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: Bug report: Model.get(pk=None)

2009-03-24 Thread Michael Glassford

Alex Gaynor wrote:
> 
> 
> On Tue, Mar 24, 2009 at 2:39 PM, Michael Glassford  > wrote:

[snip model definition, etc.]

> When I run the tests under Django 0.96.3, I get the expected exception:
> "DoesNotExist: ModelA matching query does not exist."
> 
> However, under Django 1.0, 1.0.1, 1.0.2, and the current trunk (revision
> 10162 at the time when I tested this), the "ModelA.objects.get(pk=None)"
> statement unexpectedly returns the object created by the
> "ModelA.objects.create()" on the previous line.
> 
> 
> Mike
> 
> 
> 
> 
> Under MySQL doing a query of the form WHERE primary_key IS NULL returns 
> the last created row.
> 
> Alex



Not here:

mysql> show create table myapp_modela;
+--+--+
| Table| Create Table 
   |
+--+--+
| myapp_modela | CREATE TABLE `myapp_modela` (
   `id` int(11) NOT NULL auto_increment,
   PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+--+--+
1 row in set (0.00 sec)

mysql> insert into myapp_modela values (1);
Query OK, 1 row affected (0.00 sec)

mysql> select * from myapp_modela where id is NULL;
Empty set (0.00 sec)





Also, that doesn't explain why Django 0.96 does what I expected.




Mike

--~--~-~--~~~---~--~~
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 as a Template Engine?

2009-03-24 Thread Dave A

Hi,

I'm new to Django -- I'm evaluating open source frameworks in an
attempt to port an existing application to a non-proprietary
platform.
I like Django, but am not sure about how to approach an application
templating function from the current system...

In short, each registered user of the system has their own copy of one
or more applications. Their copies holds their data, their
configurations, etc. The main web site lets them add/remove
applications, and provides links into each personal application to
view/manage their data.
Each night, a process runs to deploy any code changes to each users
application.

I'd love to build a similar system in Django, where a user can
register, select applications to use, and have their own personal
data, navigation, and views of their data, while providing my team
with an easy way to create and deploy new applications to the site.
I'm just not sure quite how to approach this...

If anyone can provide guidance to an appropriate architecture for this
type of function withing a Django platform, it would be greatly
appreciated..

Thanks...
-Dave

--~--~-~--~~~---~--~~
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: Bug report: Model.get(pk=None)

2009-03-24 Thread Alex Gaynor
On Tue, Mar 24, 2009 at 2:39 PM, Michael Glassford wrote:

>
> I haven't been able to debug why this is happening yet (I spent most of
> today narrowing down the problem to a simple test case), but if I create
> a new Django project, add a new app to it, change settings.py to have
> the appropriate db information (I'm using MySQL), and INSTALLED_APPS
> setting, then define these two files:
>
>
> myapp/models.py
> ---
> from django.db import models
>
> class ModelA(models.Model):
> pass
>
>
>
> myapp/tests.py
> --
> from django.test import TestCase
>
> from myapp.models import ModelA
>
> class MyTestCase(TestCase):
> def testBug(self):
> ModelA.objects.create()
> b = ModelA.objects.get(pk=None) #pk=None shouldn't match anything
> self.assert_(b is None, 'Unexpectedly found ModelA with id %s'
> % (b.id))
>
>
>
> When I run the tests under Django 0.96.3, I get the expected exception:
> "DoesNotExist: ModelA matching query does not exist."
>
> However, under Django 1.0, 1.0.1, 1.0.2, and the current trunk (revision
> 10162 at the time when I tested this), the "ModelA.objects.get(pk=None)"
> statement unexpectedly returns the object created by the
> "ModelA.objects.create()" on the previous line.
>
>
> Mike
>
>
> >
>
Under MySQL doing a query of the form WHERE primary_key IS NULL returns the
last created row.

Alex

-- 
"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
-~--~~~~--~~--~--~---



Bug report: Model.get(pk=None)

2009-03-24 Thread Michael Glassford

I haven't been able to debug why this is happening yet (I spent most of 
today narrowing down the problem to a simple test case), but if I create 
a new Django project, add a new app to it, change settings.py to have 
the appropriate db information (I'm using MySQL), and INSTALLED_APPS 
setting, then define these two files:


myapp/models.py
---
from django.db import models

class ModelA(models.Model):
 pass



myapp/tests.py
--
from django.test import TestCase

from myapp.models import ModelA

class MyTestCase(TestCase):
 def testBug(self):
 ModelA.objects.create()
 b = ModelA.objects.get(pk=None) #pk=None shouldn't match anything
 self.assert_(b is None, 'Unexpectedly found ModelA with id %s' 
% (b.id))



When I run the tests under Django 0.96.3, I get the expected exception: 
"DoesNotExist: ModelA matching query does not exist."

However, under Django 1.0, 1.0.1, 1.0.2, and the current trunk (revision 
10162 at the time when I tested this), the "ModelA.objects.get(pk=None)" 
statement unexpectedly returns the object created by the 
"ModelA.objects.create()" on the previous line.


Mike


--~--~-~--~~~---~--~~
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: Working With ModelForms

2009-03-24 Thread Darren Mansell
That was a great help thanks. I also used the copy() method on the
request.POST dict and I could redirect to the same view. Cheers.

On Mar 24, 2009 3:43 PM, "Thomas Guettler"  wrote:


Hi,

my guess: You need to redirect after POST.

if you give request.POST to the Form, it will overwrite the values
from the model with the values from request.POST. If you do a redirect
after POST, the value from the model will be displayed, since POST
is empty after the redirect.

BTW, I often do it like this:

def view(request):
   if request.POST:
   data=request.POST
   else:
   data=None
   form=MyForm(data)

Why do you access 'build_release' in POST? It would be better
the create a Field for it and access form.cleaned_data['build_release']

 HTH,
  Thomas

DarrenM schrieb:
> ...

> elif request.POST['build_release']: > f = BuildForm(request.POST) > ...
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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: Having trouble authenticating/validating

2009-03-24 Thread Adam Yee



On Mar 23, 8:30 pm, Karen Tracey  wrote:
> On Mon, Mar 23, 2009 at 4:45 PM, Adam Yee  wrote:
>
> > I'm using Django's builtin AuthenticationForm
>
> > Here's my login view:http://dpaste.com/18110/
>
> > Form submittal (not empty or empty fields) takes me back to the login
> > page with 'Did not login'.  My debugging print statement isn't showing
> > up in the terminal, so is_valid is somehow returning false.
>
> > If I submit with empty fields, I don't get the default 'This field is
> > required' type of error messages that I would expect.  I'm not sure
> > how clean() is working with the AuthenticationForm...  Am I validating
> > correctly? Or is something happening in the authentication process?
> > Thanks.
>
> Your error() function is creating a brand-new blank AuthenticationForm that
> is passed in the context to the template, so the specific error message
> associated with whatever caused is_valid() to fail (which has been added to
> the original form's error_list) is being thrown away.  If instead you pass
> back the form you called is_valid() on, then the template would be able to
> report the specific error that is causing the validation failure.
>
> Karen

Thanks Karen for that tip.  The brand-new unbound form is removed.

So, I now pass the bound form, but still no validation error messages
show up.  More importantly, is_valid is still returning false even
when I try logging in as a super user.  I also removed checking for
is_active since the AuthenticationForm's clean should take care of
that and raise the correct validation error if the user isn't active.
Now with the error() func removed:

def stl_login(request):
if request.method == "POST":
form = AuthenticationForm(request.POST)
if form.is_valid(): # authenticate() should get called here from
form's clean()
print 'form is valid'
user = form.get_user()
print request.user
login(request, user)
return HttpResponseRedirect(reverse
('stlhome.views.stl_user_home'))
return render_to_response('stl_home.html', {
'script_name': request.META['SCRIPT_NAME'],
'form': form,
'error': 'Did not login'}
)
--~--~-~--~~~---~--~~
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: Strip empty lines in rendered templates?

2009-03-24 Thread chachra

Would the {% spaceless %} template tag be helpful here ? I posted a
similar question, and someone responded saying that may be the way to
go.

Cheers!
Sumit


On Mar 16, 9:45 am, Benjamin Buch  wrote:
> Yes, you're right.
>
> But as the SpacelessMiddleware uses djangos' strip_spaces_between_tags,
> which strips all whitespace between tags and not just empty lines,
> I think it would have been fiddly to adapt it without touching django  
> internals.
> In this case it seemed easier for me to use StripWhitespaceMiddleware,  
> which did what I wanted.
>
> benjamin
>
> Am 16.03.2009 um 17:37 schrieb Dougal Matthews:
>
> > You could adapt that middlewear to make it only stop blank lines I'm  
> > sure.
>
> > I use it for one website and its only used in the production  
> > version, in my settings for the dev version it doesn't include that  
> > middlewear so it doesn't effect any front end development.
>
> > Only thing to be aware of is it messes up some tags, like   
> > and 
>
> > Dougal
--~--~-~--~~~---~--~~
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: Garbage Collection(maybe?) and RequestContext

2009-03-24 Thread Keyton Weissinger

Something deep inside kept telling me it was something like that.
Grrr Love making the noob mistakes. NOT!

;-)

Thanks DR!

On Mar 24, 11:57 am, Daniel Roseman 
wrote:
> On Mar 24, 3:42 pm, Keyton Weissinger  wrote:
>
> > I'm using the extra_context dictionary passed into the view like many
> > folks (James Bennett among them) seem to recommend either directly or
> > via his projects.
>
> > Here is what a view might look like (all of this is on dpaste with
> > link below if you'd prefer):
>
> > from django.shortcuts import render_to_response
> > from django.template import RequestContext
>
> > def test_view(request, template_name='test_view.html', extra_context=
> > {}):
>
> No need to read any further: you have run up against one of the
> biggest Python gotchas. Never put a mutable type as a default argument
> in a function call. This is because the definition is evaluated only
> once, so you get the same values each time you call the function. More
> explanation from the effbot here:http://effbot.org/zone/default-values.htm
>
> As that page shows, the answer is:
> def test_view(request, template_name='test_view.html',
>                     extra_context=None)
>     if extra_context is None:
>         extra_context = {}
>
> etc.
> --
> 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: OT: svn and '$Id$'

2009-03-24 Thread Alan

Hi guys, tanks for your help but I am definitely doning something
wrong because I don't get what I want.

So, I am trying this:

I have this line in my *.py file:

repositoryId = '$Id $' + '$Revision$' + '$Date$'

I did:
find . -name "*.py" -exec svn propset svn:keywords "Date" {} \;
find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;

and I also have in my ~/.subversion/config:
enable-auto-props = yes
*.py = svn:keywords=Id;svn:eol-style=native

So, when I commit my file, I was expecting to see something change in
" repositoryId = '$Id $' + '$Revision$' + '$Date$' ", like I would see
if I were using CVS.

I am using Eclipse btw, but svn ci is not doing better either.

Many thanks,
Alan

On Mar 24, 5:25 pm, David Lindquist  wrote:
> On Mar 24, 2009, at 10:09 AM, Alan wrote:
>
>
>
>
>
> > Hi there,
>
> > It's a bit off topic but I guess appropriate anyway.
>
> > So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> > when I commit my files via svn.
>
> > But I googled and I still couldn't make it work. Can somebody tell  
> > to make it work? I would like to get at least date and time when  
> > the files are committed ( svn on googlecode) in the file itself.
>
> > Many thanks in advance.
>
> > Alan
>
> > --
> > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> > Department of Biochemistry, University of Cambridge.
> > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> > >>http://www.bio.cam.ac.uk/~awd28<<
>
> Rather, that should be:
>
> find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;
>
>
>
>
--~--~-~--~~~---~--~~
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: TemplateDoesNotExist at /admin/ on Linux (Xubuntu) while doing Django Tutorial 2

2009-03-24 Thread brad



On Mar 2, 10:14 am, Karen Tracey  wrote:
> On Sun, Mar 1, 2009 at 10:56 PM, Chris Verehhotti <
>
> chris.peresso...@gmail.com> wrote:
>
> > > however, in my Thunar file viewer, every icon has a little "X" on it
> > > -- this makes me think it's a permissions issue, but I'm a Linux n00b
> > > and am not sure how to go about fixing this.  Do I need to do some
> > > kind of recursive chmod on the entire django tree in site-packages?
>
> > So.  Probably was a stupid question, and I pretty much had my
> > answer... looked a *nix tutorial about chmod, realized that every file
> > in that django site-package was 700.  I performed chmod -R 755 on the
> > whole thing and it works.
>
> How did you install Django?  It should not have been necessary to fix up the
> permissions after install, and it's not something I can remember hearing
> from anyone else, so whatever install method you used seems to have been a
> bit unusual and somewhat broken
>
> Karen


I've just installed Django-1.0.2-final on a Red Hat Linux system, and
I've also run into this problem (TemplateDoesNotExist at /admin/).
I installed django the using "python setup.py install", and all of the
admin templates (located in /usr/local/lib/python2.6/site-packages/
django/contrib/admin/templates/admin) had rw permissions for the user
and r for the group, but no permissions for others.

I'm not sure, but one possible cause of this may relate to the umask
of the user who unpacks the original Django source code (My umask is
0007).  When Django is installed, does it preserve some file
permissions?
--~--~-~--~~~---~--~~
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: OT: svn and '$Id$'

2009-03-24 Thread David Lindquist

On Mar 24, 2009, at 10:09 AM, Alan wrote:

> Hi there,
>
> It's a bit off topic but I guess appropriate anyway.
>
> So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> when I commit my files via svn.
>
> But I googled and I still couldn't make it work. Can somebody tell  
> to make it work? I would like to get at least date and time when  
> the files are committed ( svn on googlecode) in the file itself.
>
> Many thanks in advance.
>
> Alan
>
> -- 
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28<<
>

Rather, that should be:

find . -name "*.py" -exec svn propset svn:keywords "Id" {} \;


> >


--~--~-~--~~~---~--~~
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: OT: svn and '$Id$'

2009-03-24 Thread David Lindquist

On Mar 24, 2009, at 10:09 AM, Alan wrote:

> Hi there,
>
> It's a bit off topic but I guess appropriate anyway.
>
> So I want to use '$Id$' in my *.py files where '$Id$' got replaced  
> when I commit my files via svn.
>
> But I googled and I still couldn't make it work. Can somebody tell  
> to make it work? I would like to get at least date and time when  
> the files are committed ( svn on googlecode) in the file itself.
>
> Many thanks in advance.
>
> Alan
>
> -- 
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28<<
>

Try this:

find . -name "*.py" -exec svn propset svn:keywords "Date" {} \;

> >


--~--~-~--~~~---~--~~
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: Local Server seems to not work with typing parameter in the url?

2009-03-24 Thread SamuelXiao

Thanks very much, it works now!

On Mar 24, 10:57 pm, Daniel Roseman 
wrote:
> On Mar 24, 2:25 pm, SamuelXiao  wrote:
>
>
>
> > I am writing a simple application which takes parameter from the url
> > and simply put it to another python app and open it.  If it is
> > successful, a content of the author's blog post will be returned.
> > The following is my code:
> > --This one works
> > #Using Django v1.02
> > #this function works well, no problem
> > #work in local server
> > #I simply callhttp://127.0.0.1:8000/mywiki/blog/getEntry.py
> > def getEntry(req,):
> >                 URL = 
> > 'http://id:passw...@www.myschool.edu/CSserver/getPost.py?
> > author=50898712'
> >                 urlread=urllib.urlopen(URL).read()
> >                 entry = handleXMLPost(urlread)
> >                 return render_to_response('testsample.html',{"entry":entry})
>
> > This one not
> > works-
> > #this function not work, why?
> > #I simply callhttp://127.0.0.1:8000/mywiki/blog/getEntry.py?author=50898712
> > def getEntry(req,**kwargs):
> >                 stdid=kwargs['author']
> >                 URL = 
> > 'http://id:passw...@www.myschool.edu/CSservergetPost.py?author=
> > %s' % stdid
> >                 urlread=urllib.urlopen(URL).read()
> >                 entry = handleXMLPost(urlread)
> >                 return render_to_response('testsample.html',{"entry":entry})
>
> > And Django debugger tells that :
> > --
> > KeyError at /mywiki/blog/getEntry.py
> > author
>
> > Request Method:         GET
> > Request URL:    http://127.0.0.1:8000/mywiki/blog/getEntry.py
> > Exception Type:         KeyError
> > Exception Value:        author
> > 
> > 
> > value of author  :
> > u'50898712'
>
> > Does anyone know what is wrong with my function?  Any help would be
> > appreciated.
>
> It doesn't work because Django doesn't pass in querystring parameters
> as kwargs to the view function.
> Instead, use request.GET['author'] to get the author variable from the
> request.
>
> --
> 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
-~--~~~~--~~--~--~---



OT: svn and '$Id$'

2009-03-24 Thread Alan
Hi there,
It's a bit off topic but I guess appropriate anyway.

So I want to use '$Id$' in my *.py files where '$Id$' got replaced when I
commit my files via svn.

But I googled and I still couldn't make it work. Can somebody tell to make
it work? I would like to get at least date and time when the files are
committed ( svn on googlecode) in the file itself.

Many thanks in advance.

Alan

-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

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



Admin Model Search issue.

2009-03-24 Thread Bobby Roberts

Hi all.  We're using a dev version somewhere post .96 and pre 1.0.  I
have an admin model as setup here:


class Admin:
list_display =
('FirstName','LastName','Organization','BZipCode','Phone','Active','CreatedDate',)
list_filter = ['CreatedDate']
fields =  (
('Contact Information', {
'fields':
('Title','Organization','FirstName','LastName','Phone','Fax',)
}),
('Billing Address', {
'fields':
('BAddress','BAddress2','BCity','BState','BZipCode','BCountry',)
}),
('Shipping Address', {
'fields':
('SAddress','SAddress2','SCity','SState','SZipCode','SCountry',)
}),
('Communication Preferences', {
'fields':
('RefreshRate','OutBidNotifications','BidNotifications','LostNotifications','EmailFormat',)
}),
('Admin Information:', {
'fields':
('AccountNum','AuthCode','CreatedDate','ModifiedDate','Active')
}),
)
search_fields =
['AccountNum','Organization','FirstName','LastName','BZipCode','Phone']


When I try to search on anything at all, the screen just blinks and
returns all of the records.  This same syntax works perfectly on
another model.  There's no error but the search function in the /admin
is not working.  Any ideas what it could be?

--~--~-~--~~~---~--~~
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: inconsistency between remove() and clear()?

2009-03-24 Thread Margie


Ok, yes, this all makes sense now.  Thanks for the explanation!

Margie

On Mar 24, 3:32 am, Russell Keith-Magee 
wrote:
> On Tue, Mar 24, 2009 at 6:10 PM, Thomas Guettler  wrote:
>
> > Hi,
>
> > book2.publisher is an attribute which was created before you deleted it.
> > If you get book2 again from Book.objects, this attribute would not exist
> > anymore.
>
> > I have not looked at the underlaying django source, but I guess that
> > remove(obj) removes the attribute from obj.
>
> > But clear() can't do this, since it does not have a reference to all
> > affected objects.
>
> Your guess at the implementation is correct. In the implementation of
> remove(), we have a handle to the object that is being removed, so we
> are able to update the value of the publisher attribute on the object.
> In the case of clear(), we don't have a handle to the object being
> updated, so we can't update the publisher attribute.
>
> Two other interesting manifestations/side effects of this behaviour
> that are worth note:
>
>  * If you have a second reference to book2, it won't be updated in the
> case of remove():
>
> >>> book1 = pub.book_set.create(title="title1")
> >>> otherbook1 = Book.objects.get(title="title1")
> ...
> >>> otherbook1.publisher
> 
> >>> pub.book_set.remove(book1)
> >>> book1.publisher
> >>> otherbook1.publisher
>
> 
>
>  * If you re-retrieve book2, the publisher attribute will be correct:>>> 
> pub.book_set.clear()
> >>> book2.publisher
> 
> >>> otherbook2 = Book.objects.get(title="title2")
> >>> otherbook2.publisher
>
> # value is none, as expected
>
> 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: replace admin login

2009-03-24 Thread Matías Costa
On Tue, Mar 24, 2009 at 1:55 PM, benjamin.wins...@googlemail.com <
benjamin.wins...@googlemail.com> wrote:

>
> Hello
>
> I have created a more robust login mechanism for my site, using
> username and password but then also other information, specific to
> each user. My main login works fine, but I want to kill the admin
> login page so that it can't be accessed (any users logging into the
> main site who qualify as user.is_admin will have access to the admin
> site still). I still have the original authentication backend in place
> - this is to partially authenticate users - and then I have a custom
> one to do the rest of the authentication. If users can access the
> default admin login, they can bypass the second stage of
> authentication.
>
> I can't just redirect /admin to another url, since the admin app uses
> this once authentication has occurred. I want to make sure no-one can
> reach the default (less secure) login page.
>
> Please, someone in the know let me know how to fix this.
>
>
You can monkey-patch / manual-decorate / whatever-you-want-to-name-it the
admin url dispatcher. In your auth system __init__.py

from django.contrib.admin import sites

def auth_decorate(admin_root)
def new_root(self, request, url):
"Catch request to test if properly authenticated"
# stuff
if auth_ok:
# continue transparently
return admin_root(self, request, url)
else:
# call FBI?
return why_are_you_hacking_me()
return new_root

sites.root = auth_decorate(sites.root)

--~--~-~--~~~---~--~~
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: Garbage Collection(maybe?) and RequestContext

2009-03-24 Thread Daniel Roseman

On Mar 24, 3:42 pm, Keyton Weissinger  wrote:
> I'm using the extra_context dictionary passed into the view like many
> folks (James Bennett among them) seem to recommend either directly or
> via his projects.
>
> Here is what a view might look like (all of this is on dpaste with
> link below if you'd prefer):
>
> from django.shortcuts import render_to_response
> from django.template import RequestContext
>
> def test_view(request, template_name='test_view.html', extra_context=
> {}):

No need to read any further: you have run up against one of the
biggest Python gotchas. Never put a mutable type as a default argument
in a function call. This is because the definition is evaluated only
once, so you get the same values each time you call the function. More
explanation from the effbot here:
http://effbot.org/zone/default-values.htm

As that page shows, the answer is:
def test_view(request, template_name='test_view.html',
extra_context=None)
if extra_context is None:
extra_context = {}

etc.
--
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
-~--~~~~--~~--~--~---



Static Content and Google App Engine

2009-03-24 Thread tgorham3

Django documentation clearly disapproves of storing static content in
a database.  Google App Engine treats blobs in the db as the norm.

Does Big Table change the rules or is it still preferable to store
static content in the file system and let a server do the heavy
lifting.

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



Is there a Country select feature in Local Flavors forms addon?

2009-03-24 Thread NoviceSortOf


I'm looking at using the USStateSelect from from
django.contrib.localflavor.us.forms, I'm curious
though if there an comparable CountrySelect
object anywhere.

Please advise.


--~--~-~--~~~---~--~~
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: Working With ModelForms

2009-03-24 Thread Thomas Guettler

Hi,

my guess: You need to redirect after POST.

if you give request.POST to the Form, it will overwrite the values
from the model with the values from request.POST. If you do a redirect
after POST, the value from the model will be displayed, since POST
is empty after the redirect.

BTW, I often do it like this:

def view(request):
if request.POST:
data=request.POST
else:
data=None
form=MyForm(data)

Why do you access 'build_release' in POST? It would be better
the create a Field for it and access form.cleaned_data['build_release']

 HTH,
   Thomas

DarrenM schrieb:
> ...
> elif request.POST['build_release']:
> f = BuildForm(request.POST)
> new_build = f.save(commit=False)
> new_build.build_path = FindPath(request.POST
> ['build_release'])
> new_build.save()
> return render_to_response('bmi/newbuild.htm',

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Garbage Collection(maybe?) and RequestContext

2009-03-24 Thread Keyton Weissinger

I'm using the extra_context dictionary passed into the view like many
folks (James Bennett among them) seem to recommend either directly or
via his projects.

Here is what a view might look like (all of this is on dpaste with
link below if you'd prefer):

from django.shortcuts import render_to_response
from django.template import RequestContext

def test_view(request, template_name='test_view.html', extra_context=
{}):
if request.method == 'POST':
print 'inside post code...'
extra_context['extra_context_test'] = 'this is a test message'
context = RequestContext(request)
for key, value in extra_context.items():
context[key] = callable(value) and value() or value
return render_to_response(template_name,
  {'form': None},
  context_instance=context)


Here's the template I'm using as well:



Here is the current value of the extra_context item 'test': 
{{ extra_context_test }}





Now, if I call this view for the first time, I get something like this
in my browser (as expected):
Here is the current value of the extra_context item 'test':
[SUBMIT_BUTTON]

I click the submit button and then I get something like this:
Here is the current value of the extra_context item 'test': this is a
test message [SUBMIT_BUTTON]

So far so good. Based on my view this is exactly what I'd expect.

Now. Open a completely new browser if possible (I did this with
Firefox for the first two steps and then IE for this next step -- all
on the same Windows XP box) and navigate to the same view (in my case:
http://127.0.0.1:8000/test_view/).

Yep, you get this again:
Here is the current value of the extra_context item 'test': this is a
test message [SUBMIT_BUTTON]

NOTE: Existence of "this is a test message" text -- even though I
didn't POST it this time.

I have ensured that the POST portion of the view is not being called
and yet the extra_context_test value in the extra_context dictionary
still seems to have a value lingering.

Now I assume that somehow magically extra_context is still in the
request object or something, but I can't explain why.

If I just move the extra_context piece out of the parameters,
everything is ducky:

def test_view(request, template_name='test_view.html'):
# THIS WORKS AS EXPECTED BUT DOESN'T ALLOW ME TO PASS STUFF IN!!!
extra_context={}
if request.method == 'POST':
print 'inside post code...'
extra_context['extra_context_test'] = 'this is a test message'
context = RequestContext(request)
for key, value in extra_context.items():
context[key] = callable(value) and value() or value
return render_to_response(template_name,
  {'form': None},
  context_instance=context)


I feel certain that there is some bigtime obvious Python or Django
reason for this behavior but I've not found it.

Thank you very much for any explanation you are able to provide.

Best,
Keyton


Code here: http://dpaste.com/18518/


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



Working With ModelForms

2009-03-24 Thread DarrenM

Hi. I'm quite new to Django so please excuse any ignorance.

I'm trying to change the value of a ModelForm attribute and execute
the same view with the altered attribute. I've read and read the
ModelForms docs but I can't grasp how to do this.

In the view the POST data comes back and I populate a ModelForm with
it:

f = BuildForm(request.POST)

I then want to alter an attribute of this object so following the docs
I save it uncommitted to get back a Model object:

new_build = f.save(commit=False)

Then I alter the attribute using a function that just returns a
string:

new_build.build_path = FindPath(request.POST['build_release'])

How do I now put this into a form that I render using the same
template/view as I'm currently using? (I've copied the whole function
below for completeness). The Model object I'm getting back from the
save() method just seems to render in the template as the value of the
primary key?

Thanks for any help.

def newbuild(request):
if request.POST:
if request.POST['build_path']:
f = BuildForm(request.POST)
f.save()
return render_to_response('bmi/thanks.htm',)
elif request.POST['build_release']:
f = BuildForm(request.POST)
new_build = f.save(commit=False)
new_build.build_path = FindPath(request.POST
['build_release'])
new_build.save()
return render_to_response('bmi/newbuild.htm',
{'request':request, 'new_build' : new_build, })
else:
form = BuildForm(initial={'created_date': datetime.datetime.now
()})
return render_to_response('bmi/newbuild.htm', {'form' : form})

--~--~-~--~~~---~--~~
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: Upload an ImageField from the Python shell

2009-03-24 Thread Matías Costa
On Tue, Mar 24, 2009 at 4:10 PM, Rit  wrote:

>
> How can I set an ImageField of a model from within the Python shell?
> >
>
ImageField and FileField are just strings. They get special treatment in
forms, OK, but your model instance attribute is just a string.

--~--~-~--~~~---~--~~
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 filed with default type set in database

2009-03-24 Thread mark

im a newbie to django. i have an existing database with default values
for field set in the database:
for example:

  created timestamp without time zone DEFAULT now(),
  number_polls integer DEFAULT 0,


i want to use django admin interface to manage tables. how do i set up
these fields in models.py, so that i can let the database set the
default values and not in django.
i tried setting null=True, and blank=True, it did not work
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
-~--~~~~--~~--~--~---



Upload an ImageField from the Python shell

2009-03-24 Thread Rit

How can I set an ImageField of a model from within the Python shell?
--~--~-~--~~~---~--~~
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: need a multiselect list box for a static list of options

2009-03-24 Thread Brian Neal

On Mar 24, 8:55 am, Adam Fraser  wrote:
> Still doesn't work.  Maybe I should be more specific.
>
> I'm editing projectprofiler/projects/models.py which hasn't needed to
> import forms for anything, and when I do I get very strange errors.
>
> Here's what it looks like now:
>
> from django.db import models
> from django.contrib.auth.models import User
> from projectprofiler.middleware import threadlocals
>
> #CHOICES defined here
> #...
>
> class Project(models.Model):
>     name  = models.CharField(max_length=200)
>     complexity                  = models.PositiveIntegerField
> (choices=COMPLEXITY_CHOICES, default=0)
>     affiliation                 = models.PositiveIntegerField
> (choices=AFFILIATION_CHOICES, default=0
>     description                 = models.TextField(max_length=300,
> blank=True) # not required
>    ...etc
>
> ...as you can see, everything is coming from django.db.models.  I have
> never had to specify the actual widgets that input the data in the
> admin pages on the site... they are just automatic.  What confuses me
> to death is how all I need to do is add "from django import forms" to
> the above code to make it break.
>
> -Adam
>

I thought you were trying to make a form. Are you trying to do all
this from the admin?
If that is the case you can provide your own form that the admin will
use. In that form is where you specify the fields and widgets you
need.
Take a look at the forms documentation and also the model-forms docs.
--~--~-~--~~~---~--~~
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: Local Server seems to not work with typing parameter in the url?

2009-03-24 Thread Daniel Roseman



On Mar 24, 2:25 pm, SamuelXiao  wrote:
> I am writing a simple application which takes parameter from the url
> and simply put it to another python app and open it.  If it is
> successful, a content of the author's blog post will be returned.
> The following is my code:
> --This one works
> #Using Django v1.02
> #this function works well, no problem
> #work in local server
> #I simply callhttp://127.0.0.1:8000/mywiki/blog/getEntry.py
> def getEntry(req,):
>                 URL = 
> 'http://id:passw...@www.myschool.edu/CSserver/getPost.py?
> author=50898712'
>                 urlread=urllib.urlopen(URL).read()
>                 entry = handleXMLPost(urlread)
>                 return render_to_response('testsample.html',{"entry":entry})
>
> This one not
> works-
> #this function not work, why?
> #I simply callhttp://127.0.0.1:8000/mywiki/blog/getEntry.py?author=50898712
> def getEntry(req,**kwargs):
>                 stdid=kwargs['author']
>                 URL = 
> 'http://id:passw...@www.myschool.edu/CSservergetPost.py?author=
> %s' % stdid
>                 urlread=urllib.urlopen(URL).read()
>                 entry = handleXMLPost(urlread)
>                 return render_to_response('testsample.html',{"entry":entry})
>
> And Django debugger tells that :
> --
> KeyError at /mywiki/blog/getEntry.py
> author
>
> Request Method:         GET
> Request URL:    http://127.0.0.1:8000/mywiki/blog/getEntry.py
> Exception Type:         KeyError
> Exception Value:        author
> 
> 
> value of author  :
> u'50898712'
>
> Does anyone know what is wrong with my function?  Any help would be
> appreciated.

It doesn't work because Django doesn't pass in querystring parameters
as kwargs to the view function.
Instead, use request.GET['author'] to get the author variable from the
request.

--
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: Languages problem

2009-03-24 Thread Muslu Yüksektepe
i want you try without

*> >def save(self):
> >if not self.pk:
> >self.secid = slugify(self.title).replace("-**", "_")
> >if MainCategory.objects.filter(**secid = self.secid):
> >super(MainCategory, self).save()
> >self.secid = "%s__%s" %(self.secid, self.pk)
> >return super(MainCategory, self).save()*

delete this code and try again

2009/3/24 alexarsh 

>
> Hi,
>
> No, I don't have any errors. I just get my title empty.
>
> Regards, Alex A.
>
> On Mar 24, 3:56 pm, Muslu Yüksektepe 
> wrote:
> > if u have a error pls write all error code.
> >
> > 2009/3/24 knight 
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > I have the following class in my models.py:
> >
> > > class MainCategory(models.Model):
> > >title = models.CharField(max_length=50)
> > >value = models.DecimalField(default=0, max_digits=5,
> > > decimal_places=3)
> > >secid = models.SlugField(max_length=1000, editable=False)
> > >def save(self):
> > >if not self.pk:
> > >self.secid = slugify(self.title).replace("-", "_")
> > >if MainCategory.objects.filter(secid = self.secid):
> > >super(MainCategory, self).save()
> > >self.secid = "%s__%s" %(self.secid, self.pk)
> > >return super(MainCategory, self).save()
> > >def __unicode__(self):
> > >return self.title
> >
> > > I have the following problem:
> > > If I create new object with title on Russian or Arabic or any other
> > > language, I see it in admin with the empty string instead of it's
> > > title.
> > > My database is postgres and its utf-8.
> > > I guess it's something to do with unicode but I can't understand what
> > > exactly.
> > > Do you have any ideas?
> >
> > > Thanks, Arshavski Alexander.
> >
> > --
> > Muslu YÜKSEKTEPE
> >
>


-- 
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: Multiple ModelAdmins for a single Model

2009-03-24 Thread Dan Ward

OK,

I've done a fair amount of research and I want to detail what I'm
aiming to achieve.

I have a page table. The page table contains various fields, which are
dependent upon the pgtype option (containing three possible values).

What I want to achieve is three separate pages in the admin site,
which show only their specified pgtype's options. Each admin page
should appear as it's own Model, seemly unrelated.

When visiting a 'Video' page, for example from the admin site, it
should only list the video pages from the pages table. When adding a
new item, it should only show only relevant 'Video' fields. This
should also be the case for 'Message' and 'Website' pages (the other
two pgtype values).

I really don't want to start going down the route of model redesign to
have separate tables. Especially as the database is already in use.

Thanks.

On Mar 24, 11:57 am, Dan Ward  wrote:
> To follow up,
>
> I can see how I can achieve different forms, however I can't figure
> out how to provide three separate links in the admin index page.
>
> Any suggestions?
>
> On Mar 22, 11:22 am, Dan Ward  wrote:
>
> > Hi,
>
> > First of all thanks for the replies. I won't be able to try anything
> > until tomorrow, however it has given some food for thought.
>
> > Malcom, the three admin entries is what I'm looking for. Essentially,
> > I'm aiming to have the admin home page display the pages block as so:
>
> > Pages (admin group)
> > -- Rotation (rotation model)
> > -- Web Page (page model)
> > -- Video Page (page model)
> > -- Message Page (page model)
>
> > The rotation page really doesn't matter. I'll look in to improvements
> > at a later stage, however the focus is on having three separate admin
> > forms for a single model. Really, looking back on it, it would have
> > been better in multiple models, but that's besides the point, I don't
> > have the time to go back on what I've done there.
>
> > I hope this clears things up a bit.
>
> > On 21 Mar, 22:04, Malcolm Tredinnick  wrote:
>
> > > On Sat, 2009-03-21 at 18:01 -0400, Alex Gaynor wrote:
>
> > > [...]
>
> > > > In the development version there's actually a more clever solution to
> > > > this.  You can create pure python subclasses(proxy classes) that use
> > > > the same DB table and fields and everything, but have their own class.
> > > > So you could create the relevant proxy models, and register the
> > > > ModelAdmins for each one of these proxy models.
>
> > > Only if the original poster wants three separate admin entries on the
> > > index page. It depends on the requirements, which hopefully the original
> > > poster will explain.
>
> > > 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: Languages problem

2009-03-24 Thread alexarsh

Hi,

No, I don't have any errors. I just get my title empty.

Regards, Alex A.

On Mar 24, 3:56 pm, Muslu Yüksektepe 
wrote:
> if u have a error pls write all error code.
>
> 2009/3/24 knight 
>
>
>
>
>
> > Hi,
>
> > I have the following class in my models.py:
>
> > class MainCategory(models.Model):
> >    title = models.CharField(max_length=50)
> >    value = models.DecimalField(default=0, max_digits=5,
> > decimal_places=3)
> >    secid = models.SlugField(max_length=1000, editable=False)
> >    def save(self):
> >        if not self.pk:
> >            self.secid = slugify(self.title).replace("-", "_")
> >            if MainCategory.objects.filter(secid = self.secid):
> >                super(MainCategory, self).save()
> >                self.secid = "%s__%s" %(self.secid, self.pk)
> >        return super(MainCategory, self).save()
> >    def __unicode__(self):
> >        return self.title
>
> > I have the following problem:
> > If I create new object with title on Russian or Arabic or any other
> > language, I see it in admin with the empty string instead of it's
> > title.
> > My database is postgres and its utf-8.
> > I guess it's something to do with unicode but I can't understand what
> > exactly.
> > Do you have any ideas?
>
> > Thanks, Arshavski Alexander.
>
> --
> 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: Local Server seems to not work with typing parameter in the url?

2009-03-24 Thread R. Gorman

If that's an exact copy, you have a typo in your URL variable; you're
missing a / after CSserver.

R.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Local Server seems to not work with typing parameter in the url?

2009-03-24 Thread SamuelXiao

I am writing a simple application which takes parameter from the url
and simply put it to another python app and open it.  If it is
successful, a content of the author's blog post will be returned.
The following is my code:
--This one works
#Using Django v1.02
#this function works well, no problem
#work in local server
#I simply call http://127.0.0.1:8000/mywiki/blog/getEntry.py
def getEntry(req,):
URL = 'http://id:passw...@www.myschool.edu/CSserver/getPost.py?
author=50898712'
urlread=urllib.urlopen(URL).read()
entry = handleXMLPost(urlread)
return render_to_response('testsample.html',{"entry":entry})


This one not
works-
#this function not work, why?
#I simply call http://127.0.0.1:8000/mywiki/blog/getEntry.py?author=50898712
def getEntry(req,**kwargs):
stdid=kwargs['author']
URL = 
'http://id:passw...@www.myschool.edu/CSservergetPost.py?author=
%s' % stdid
urlread=urllib.urlopen(URL).read()
entry = handleXMLPost(urlread)
return render_to_response('testsample.html',{"entry":entry})

And Django debugger tells that :
--
KeyError at /mywiki/blog/getEntry.py
author

Request Method: GET
Request URL:http://127.0.0.1:8000/mywiki/blog/getEntry.py
Exception Type: KeyError
Exception Value:author


value of author  :
u'50898712'

Does anyone know what is wrong with my function?  Any help would be
appreciated.

--~--~-~--~~~---~--~~
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 deploying requirements

2009-03-24 Thread marx.r...@googlemail.com

Hello

i have some question on hardware req. for a new project we are going
to deploy soon.
First some facts on the expected traffic.

- 200k to 500k Users in complete
- 2k to 5k concurrent users on the page
- every page consists of something about 10 to 20 database accesses
- applications include only textual data like forums, messages and
other custom designed functions. No flash/video and such stuff :)
- max db-data per user will be somthing about 1 megabyte

My question would be how to set up the right deployment enviroment in
hardware terms.

I thought about having:

1 DB server
  - 1 x Intel® Xeon(TM) X5482 Processor 3.2GHz
  - 8 GB Ram

1 Web(App) serevr
  - 1 or 2 x Intel® Xeon(TM) X5482 Processor 3.2GHz
  - 16 GB Ram

(probably) 1 memcached serevr
  - Intel® Xeon(TM) E5430 Processor 2.66GHz
  - 32 GB Ram

1 utility server (for doing stuff like sending mails (using django-
mailer) and backups)

This is what will run on the servers:
- Ubuntu Server
- python 2.5.2
- django 1.0.2
- postgres 8.3
(- memcached 1.2.6)


This is my first project in django so i don't have any expirience in
deploying. Thats why i'd like to
optain your opinion if my thoughts are realizable.

Oh and one more question:
Is there something special to care about when running django (python)
on a multiprocessor machine?

Any advices or references are very welcome.

Many thanks

PS: django rules. I started some month before and begining to realy
love 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: Languages problem

2009-03-24 Thread Muslu Yüksektepe
if u have a error pls write all error code.

2009/3/24 knight 

>
> Hi,
>
> I have the following class in my models.py:
>
> class MainCategory(models.Model):
>title = models.CharField(max_length=50)
>value = models.DecimalField(default=0, max_digits=5,
> decimal_places=3)
>secid = models.SlugField(max_length=1000, editable=False)
>def save(self):
>if not self.pk:
>self.secid = slugify(self.title).replace("-", "_")
>if MainCategory.objects.filter(secid = self.secid):
>super(MainCategory, self).save()
>self.secid = "%s__%s" %(self.secid, self.pk)
>return super(MainCategory, self).save()
>def __unicode__(self):
>return self.title
>
> I have the following problem:
> If I create new object with title on Russian or Arabic or any other
> language, I see it in admin with the empty string instead of it's
> title.
> My database is postgres and its utf-8.
> I guess it's something to do with unicode but I can't understand what
> exactly.
> Do you have any ideas?
>
> Thanks, Arshavski Alexander.
> >
>


-- 
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: need a multiselect list box for a static list of options

2009-03-24 Thread Adam Fraser

Still doesn't work.  Maybe I should be more specific.

I'm editing projectprofiler/projects/models.py which hasn't needed to
import forms for anything, and when I do I get very strange errors.

Here's what it looks like now:

from django.db import models
from django.contrib.auth.models import User
from projectprofiler.middleware import threadlocals

#CHOICES defined here
#...

class Project(models.Model):
name  = models.CharField(max_length=200)
complexity  = models.PositiveIntegerField
(choices=COMPLEXITY_CHOICES, default=0)
affiliation = models.PositiveIntegerField
(choices=AFFILIATION_CHOICES, default=0
description = models.TextField(max_length=300,
blank=True) # not required
   ...etc


...as you can see, everything is coming from django.db.models.  I have
never had to specify the actual widgets that input the data in the
admin pages on the site... they are just automatic.  What confuses me
to death is how all I need to do is add "from django import forms" to
the above code to make it break.

-Adam


Brian Neal wrote:
> On Mar 23, 3:36 pm, Adam Fraser  wrote:
> > I found the SelectMultiple widget here:
> >
> > http://docs.djangoproject.com/en/dev/ref/forms/widgets/
> >
> > But I still don't know how to hook that up to a model like
> > CommaSeparatedIntegerField.
> >
> > help?
> >
>
> Did you try something like this? This is off the top of my head:
>
> class MyForm(forms.ModelForm):
>my_choices = forms.CommaSeparatedIntegerField
> (widget=forms.SelectMultiple(choices=STAIN_CHOICES))
>
> See:
> http://docs.djangoproject.com/en/dev/ref/forms/widgets/#specifying-widgets
--~--~-~--~~~---~--~~
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: mod_python and Dev server compatible coding

2009-03-24 Thread Ross

The big value for me of the dev server is the ease with which I can
get debugging information out of it.

Of course, I fully understand that it is not suitable for serving my
site - I didn't mean to give the impression that it was. But the cycle
of using the dev-server for making something work, then moving
everything onto the production server seems like an path that most
people would want.

Getting info out of my views.py code while I'm hacking something up is
pretty tough otherwise.

Thanks for clarifying that the 'trigger' word is called the
SCRIPT_NAME.

I'll look around for something that clarifies how to use SCRIPT_NAME
properly - I guess that's really what my whole question was.  Any
suggestions where to find examples for that?

Ross.



On Mar 23, 9:03 pm, Malcolm Tredinnick 
wrote:
...snip...
>
> If the dev server doesn't meet your needs and you need a full webserver,
> then do exactly that: use a full-powered web server. Normally, though,
> this shouldn't really matter. All the links within your site can be made
> to work without caring about the SCRIPT_NAME (e.g. the "url" template
> tag adds it when required), so it's good practice to build your site
> being able to move it to a different SCRIPT_NAME prefix.
>
> 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
-~--~~~~--~~--~--~---



GeoDjango - Multiple Features in Shapefile

2009-03-24 Thread Alfonso

Hi, I have a shapefile of England loaded into a geodjango model that
is a combination of administrative boundaries (counties essentially)
of the entire country.  I'm trying to put together a query search that
will return activities by country (then ultimately county) but
layermapping has loaded the shapefile features as separate records
(which was anticipated).  So my question is - is it possible in
GeoDjango to query multiple shapefile features at once to determine if
'Swimming Activity' is in 'England'?  I guess its a kind of 'search
for results in all england counties'.

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



Django + mod_python + apache on development box

2009-03-24 Thread douglas

I am a django newbie having difficulty getting django operational on
my development box running on Apache, with mod_python.  My Django test
case - the sitepoint.com tutorial: 
http://www.sitepoint.com/article/build-to-do-list-30-minutes/
- renders as HTML, but [Apache? Mod_python?] can not find the CSS
formatting code to render the pages as designed.  See media directory
below.

I have not used mod_python before, but I did install it (see system
description below) and it did pass the basic test proposed by the
mod_python installer.  See (**) below.  So i know that it knows to use
mod_python to resolve all addresses ending in ".py".  Also, Django
pages render as expected with the Django lightweight web server for
testing.

I am seem to be close to success.  I am going to spend time with the
documentation today.  Any suggestions would be greatly appreciated.

Best regards,
Douglas


a) HTTPD.conf location directive follows:

SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE gtd.settings
PythonDebug On
PythonOption django.root "/gtd"
PythonPath "sys.path+['C:/apps/myDjango']"


b) System Set-up
Operating system:  vista
dbase:  mysql 5.0
server:  localhost
webservice port:  81
Apache:  v2.2
Python:  v2.5
mod_python:  v3.3.1

c) Directory python:  C:\python25
d) Directory django:  C:\Python25\Lib\site-packages\django
e) Directory Django sitepoint application:  C:\apps\myDjango
f) Directory django media:  C:/Python25/Lib/site-packages/django/
contrib/admin/media

**  mod_python installer test:

1) Add to HTTPD.conf:

AddHandler mod_python .py
PythonHandler mptest
PythonDebug On


2) Create file with the following code:
from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

3) request page:  http://localhost:81/test/mptest.py

4) "mptest.py" file is located undeer "htdocs" (C:\Program Files
\Apache Software Foundation\Apache2.2\htdocs\test), and my django
files are NOT.  I assume that the django set-up creates a special
configuration requirement.

--~--~-~--~~~---~--~~
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 book mostly done?

2009-03-24 Thread brad



On Mar 23, 8:15 pm, Malcolm Tredinnick 
wrote:
> On Mon, 2009-03-23 at 15:08 -0700, Graham Dumpleton wrote:
>
> [...]
>
> > More of a concern is that mod_python is still regarded as the most
> > robust production setup. I can't see that mod_wsgi is even mentioned
> > at all.
>
> Here's a wild thought from out of left field: have you thought of
> contacting the author of said book and mentioning it to him? Adrian (the
> author) doesn't read this group, so this approach isn't going to work.
>
> Malcolm

There's actually this cool commenting system for the Django Book's
website.
You could leave comments there (and in fact, this very comment has
already been posted)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



replace admin login

2009-03-24 Thread benjamin.wins...@googlemail.com

Hello

I have created a more robust login mechanism for my site, using
username and password but then also other information, specific to
each user. My main login works fine, but I want to kill the admin
login page so that it can't be accessed (any users logging into the
main site who qualify as user.is_admin will have access to the admin
site still). I still have the original authentication backend in place
- this is to partially authenticate users - and then I have a custom
one to do the rest of the authentication. If users can access the
default admin login, they can bypass the second stage of
authentication.

I can't just redirect /admin to another url, since the admin app uses
this once authentication has occurred. I want to make sure no-one can
reach the default (less secure) login page.

Please, someone in the know let me know how to fix this.

Benjamin

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



Languages problem

2009-03-24 Thread knight

Hi,

I have the following class in my models.py:

class MainCategory(models.Model):
title = models.CharField(max_length=50)
value = models.DecimalField(default=0, max_digits=5,
decimal_places=3)
secid = models.SlugField(max_length=1000, editable=False)
def save(self):
if not self.pk:
self.secid = slugify(self.title).replace("-", "_")
if MainCategory.objects.filter(secid = self.secid):
super(MainCategory, self).save()
self.secid = "%s__%s" %(self.secid, self.pk)
return super(MainCategory, self).save()
def __unicode__(self):
return self.title

I have the following problem:
If I create new object with title on Russian or Arabic or any other
language, I see it in admin with the empty string instead of it's
title.
My database is postgres and its utf-8.
I guess it's something to do with unicode but I can't understand what
exactly.
Do you have any ideas?

Thanks, Arshavski Alexander.
--~--~-~--~~~---~--~~
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: Templating language Include path dilemma

2009-03-24 Thread Colm



On Mar 24, 12:42 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-03-23 at 17:21 +, Colm Dougan wrote:
>
>
> There is, however, no concept of "context" passed through to the
> template loader. Everything is loaded from the same base situation,
> which is what I believe your question is asking. The relevant code is in
> django/template/loader_tags.py.

I understand.  Apologies for my sloppy terminology wrt. "document
root".  I just meant "the templates folder"   Unfortunately I don't
know python so just to make sure I'm clear, I'm going to restate my
question based on what you have said.

Assuming I had only one app called "foo_app" and my templates were
laid out as follows :

  foo_app/template/template1
  foo_app/template/path1/template2
  foo_app/template/path2/template3

Assuming foo_app/template/template1 looks like this :

{% include "path1/temtlate2" %}

If template2 wants to include template3 should it do this :

   { % include "../path2/template3" %}

OR this :

  {% include "path2/template3" %}

>From what you have said I'm gathering it is the latter.  Is that
correct?

Also, is the former idiom (the use of "..") meaningful at all when
evaluating includes and if so what does it mean?   If it is meaningful
at all does it mean "relative to the templates directory"? i.e. if I
had :

   templates/foo
   otherstuff/blah

.. could I include "blah" by saying {% include "../otherstuff/blah"
%}.  Or does that not make sense?

Thanks,
Colm

--~--~-~--~~~---~--~~
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: JSON Model Serialization

2009-03-24 Thread gchuyun

i tried this, but get a error similar.

TypeError: [{'publish_time': datetime.datetime(2009, 3, 24, 16, 16,
18), 'is_deleted': 0, 'is_confirmed'
: 0, 'title': u'1', 'content': u'111', 'id': 1L}, {'publish_time':
datetime.datetime(2009, 3, 24, 16
, 27, 50), 'is_deleted': 0, 'is_confirmed': 0, 'title': u'12',
'content': u'22', 'id': 2L}, {'publish_time'
: datetime.datetime(2009, 3, 24, 16, 28, 50), 'is_deleted': 0,
'is_confirmed': 0, 'title': u''
, 'content': u'', 'id': 3L}] is not JSON serializable


On Mar 16, 6:44 am, Mateusz Wawrzyniak 
wrote:
> On Mar 14, 10:14 pm, MartinBorthiry  wrote:
>
> > Hello:
>
> >  I'm Trying to serialize a dict which have a list of Model's instance.
> > The format that i need is json. Something  like that:
>
> >     people = Person.objects.all()
>
> Why don't you use Person.objects.values()?
> You will get a list of dicts so there won't be any problems with
> serialization.

--~--~-~--~~~---~--~~
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: Multiple ModelAdmins for a single Model

2009-03-24 Thread Dan Ward

To follow up,

I can see how I can achieve different forms, however I can't figure
out how to provide three separate links in the admin index page.

Any suggestions?

On Mar 22, 11:22 am, Dan Ward  wrote:
> Hi,
>
> First of all thanks for the replies. I won't be able to try anything
> until tomorrow, however it has given some food for thought.
>
> Malcom, the three admin entries is what I'm looking for. Essentially,
> I'm aiming to have the admin home page display the pages block as so:
>
> Pages (admin group)
> -- Rotation (rotation model)
> -- Web Page (page model)
> -- Video Page (page model)
> -- Message Page (page model)
>
> The rotation page really doesn't matter. I'll look in to improvements
> at a later stage, however the focus is on having three separate admin
> forms for a single model. Really, looking back on it, it would have
> been better in multiple models, but that's besides the point, I don't
> have the time to go back on what I've done there.
>
> I hope this clears things up a bit.
>
> On 21 Mar, 22:04, Malcolm Tredinnick  wrote:
>
> > On Sat, 2009-03-21 at 18:01 -0400, Alex Gaynor wrote:
>
> > [...]
>
> > > In the development version there's actually a more clever solution to
> > > this.  You can create pure python subclasses(proxy classes) that use
> > > the same DB table and fields and everything, but have their own class.
> > > So you could create the relevant proxy models, and register the
> > > ModelAdmins for each one of these proxy models.
>
> > Only if the original poster wants three separate admin entries on the
> > index page. It depends on the requirements, which hopefully the original
> > poster will explain.
>
> > 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: Why save on attributes is no good?

2009-03-24 Thread Briel

Hi

I'm not sure exactly how this work, but.
Your problem is how the data is saved and retrieved.If you do
self.sm_id
after the save(), you will get the id by reference, but when the model
itself needs to be saved, it need the data itself, which it hasn't, or
something like that

Anyways, to get it to work you need to do it like this:

> self.sm = SomeModel()
> self.sm.save()
self.sm = self.sm
self.save()

~Jakob
--~--~-~--~~~---~--~~
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 with wing IDE

2009-03-24 Thread Lakshman Prasad
Hi,

With the latest beta version of Wing 3.2, the auto complete of attributes
happen during debug, by sniffing the current python namespace.

This means that, even the ORM objects should auto complete in the IDE.

But hooking wing run to django run server itself is a huge process.

Can somebody who has successfully accomplished both suggest me how to, or
guide me to appropriate resources, if any.

Thanks in advance!

-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

--~--~-~--~~~---~--~~
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 admin

2009-03-24 Thread Lakshman Prasad
Hi,

I was thinking that django admin is an utility to provide trusted
administrators of the site, full access to the site's data model.

However, after going through django admin in detail, I understand that it is
very powerful set of views and templates that one can use to create an
entire application.

How often do you create an entire application using admin alone? Is it
easier to create using views itself than customising admin that much?

How about building prototype using admin. Do we even need to build
prototype? The admin customization cannot be re-used in real application.

If I want to use a part of the admin code in real application (with
different templates), is there some kind of scaffolding option available?

Thanks in advance!

-- 
Regards,
Lakshman
uswaretech.com
becomingguru.com
lakshmanprasad.com

--~--~-~--~~~---~--~~
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: inconsistency between remove() and clear()?

2009-03-24 Thread Russell Keith-Magee

On Tue, Mar 24, 2009 at 6:10 PM, Thomas Guettler  wrote:
>
> Hi,
>
> book2.publisher is an attribute which was created before you deleted it.
> If you get book2 again from Book.objects, this attribute would not exist
> anymore.
>
> I have not looked at the underlaying django source, but I guess that
> remove(obj) removes the attribute from obj.
>
> But clear() can't do this, since it does not have a reference to all
> affected objects.

Your guess at the implementation is correct. In the implementation of
remove(), we have a handle to the object that is being removed, so we
are able to update the value of the publisher attribute on the object.
In the case of clear(), we don't have a handle to the object being
updated, so we can't update the publisher attribute.

Two other interesting manifestations/side effects of this behaviour
that are worth note:

 * If you have a second reference to book2, it won't be updated in the
case of remove():

>>> book1 = pub.book_set.create(title="title1")
>>> otherbook1 = Book.objects.get(title="title1")
...
>>> otherbook1.publisher

>>> pub.book_set.remove(book1)
>>> book1.publisher
>>> otherbook1.publisher


 * If you re-retrieve book2, the publisher attribute will be correct:
>>> pub.book_set.clear()
>>> book2.publisher

>>> otherbook2 = Book.objects.get(title="title2")
>>> otherbook2.publisher
# value is none, as expected

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



Why save on attributes is no good?

2009-03-24 Thread Filip Gruszczyński

If I create some model like this, it's ok:

sm = SomeModel()
sm.save()
self.sm = sm

But if I try to this:

self.sm = SomeModel()
self.sm.save()

Then when I try to save self, OtherModel.save(self), because it wasn't
yet saved I receive information, that self.sm id wasn't set (and it
can't be null). Why it happens so?

-- 
Filip Gruszczyński

--~--~-~--~~~---~--~~
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: inconsistency between remove() and clear()?

2009-03-24 Thread Thomas Guettler

Hi,

book2.publisher is an attribute which was created before you deleted it.
If you get book2 again from Book.objects, this attribute would not exist
anymore.

I have not looked at the underlaying django source, but I guess that
remove(obj) removes the attribute from obj.

But clear() can't do this, since it does not have a reference to all
affected objects.

  Thomas

Margie schrieb:
> It seems to me there is an inconsistency between clear() and remove
> ().  After a remove() I find that the related object set no longer
> contains the specified object (as expected), and the specified object
> also no longer points to the related set (this also is what I'd
> expect).  However, in the case of clear(), I find that the related
> object set is now cleared out (as I'd expect), but the objects that
> used to be in the set still point to the set (not what I'd expect).
> Is this difference intentional?
> 
> I also find that after exiting the shell and then going back in, now
> the objects that used to be in the set no longer point to the set.
> IE, the inconsistent clear behavior goes away if I exit the django
> shell and then re-enter.
> 
> class Publisher(models.Model):
> name = models.CharField(max_length=100)
> 
> class Book(models.Model):
> title = models.CharField(max_length=100)
> publisher = models.ForeignKey(Publisher, blank=True, null=True)
> 
 pub = Publisher.objects.create(name="pub1")
 book1 = pub.book_set.create(title="title1")
 pub.book_set.all()
> []
 book2 = pub.book_set.create(title="title2")
 pub.book_set.all()
> [, ]
 book1.publisher
> 
 book2.publisher
> 
> 
> # after using remove() to remove book1, book1.publisher is empty
 pub.book_set.remove(book1)
 book1.publisher
 pub.book_set.all()
> []
> 
> # Now book2 references pub.  After using clear(), book2.publisher
> still references pub
> # This seems inconsistent with the remove() behavior above.
 pub.book_set.clear()
 book2.publisher
> 
> 
> Any comments from those in-the-know?
> 
> Margie
> 


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: Reverse tag of safe

2009-03-24 Thread Thomas Guettler

Hi,

google for "entity resolver python". I recall that I did something like this.

You could ask on comp.lang.python, too.

If you got it working in python you can create a template tag.

 Thomas

Alessandro Ronchi schrieb:
> I need to translate html entities on utf-8 characters, like  to à
> is there any template tag filter which can do that?
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: ModelChoiceField - large lookup tables

2009-03-24 Thread Thomas Guettler

Hi,

for the Admin Interface there is raw_id_fields.

In the code of my application I use my ButtonWidget.
It renders itself as a hidden Input field and a button. If you
click on the button you get a query page to search for the related
object. After selection it writes the value back to the hidden field
with JS opener.document.getElementById(...);

That's my way, I guess there exist better solutions.

  Thomas

PNM schrieb:
> Before I re-invent the wheel: is there any generally accepted or
> recommended generic way to handle ModelChoiceFields with very large
> datasets in Django?
> 
> My current example is an address>post/ZIP-code relationship where
> Django's automatic field creation pulls in the whole postcode table
> with thousands of rows into a ModelChoiceField.
> 
> The postcode field changes relatively seldom, so a sensible solution
> would seem to be some sort of passive display-only field which mirrors
> the choice field's functionality (show the link's __unicode__ and hold
> the link's pk for form validation), and that the mechanism for pulling
> in a new value is put somewhere else (eg. a button to open a search-
> and-select window). A ModelLookupField?
> 
> This must be such a common scenario that I'd be interested in hearing
> how other people solve it. I can't find anything in the documenation
> on it.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



ModelChoiceField - large lookup tables

2009-03-24 Thread PNM

Before I re-invent the wheel: is there any generally accepted or
recommended generic way to handle ModelChoiceFields with very large
datasets in Django?

My current example is an address>post/ZIP-code relationship where
Django's automatic field creation pulls in the whole postcode table
with thousands of rows into a ModelChoiceField.

The postcode field changes relatively seldom, so a sensible solution
would seem to be some sort of passive display-only field which mirrors
the choice field's functionality (show the link's __unicode__ and hold
the link's pk for form validation), and that the mechanism for pulling
in a new value is put somewhere else (eg. a button to open a search-
and-select window). A ModelLookupField?

This must be such a common scenario that I'd be interested in hearing
how other people solve it. I can't find anything in the documenation
on 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: Reverse tag of safe

2009-03-24 Thread Malcolm Tredinnick

On Tue, 2009-03-24 at 09:18 +0100, Alessandro Ronchi wrote:
> I need to translate html entities on utf-8 characters, like 
> to à
> is there any template tag filter which can do that?

Not in the core distribution, no. I don't know if there's any
third-party filter to do so.

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



Reverse tag of safe

2009-03-24 Thread Alessandro Ronchi
I need to translate html entities on utf-8 characters, like  to à
is there any template tag filter which can do that?

-- 
Alessandro Ronchi
Skype: aronchi
http://www.alessandroronchi.net

SOASI Soc.Coop. - www.soasi.com
Sviluppo Software e Sistemi Open Source
Sede: Via Poggiali 2/bis, 47100 Forlì (FC)
Tel.: +39 0543 798985 - Fax: +39 0543 579928

Rispetta l'ambiente: se non ti è necessario, non stampare questa mail

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