Re: my models are remembering old fields that I have since deleted

2011-05-07 Thread Nick Arnett
On Sat, May 7, 2011 at 6:50 PM, George Silva wrote:

> Just drop the old tables and run syncdb again!


I didn't think it was safe to assume that he wanted to throw away all of his
data...

Nick

-- 
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: my models are remembering old fields that I have since deleted

2011-05-07 Thread Nick Arnett
On Sat, May 7, 2011 at 6:05 PM, Dug_the_Math_Guy wrote:

> HI I'm new to Django and just getting some models going. I started
> with a more complex model and got errors so I scaled back to a more
> minimalist model to see if I could get that working. I flushed my
> database to get rid of any old info and synched the DB to create the
> new more minimal models.


Syncing the database doesn't delete anything, ever.  Probably the simplest
way to deal with this is to rename (in the database) the tables that you
have changed, then run syncdb to create your new tables, then copy the old
data into the new tables and delete the old tables.

If by "flushed" you mean you deleted the old tables (or the whole database),
then something else is going on.

Nick

-- 
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: Best Practice for Raw SQL

2011-04-13 Thread Nick Arnett
On Wed, Apr 13, 2011 at 1:38 PM, Sells, Fred
wrote:

> In my case I had to read some legacy data from a different schema on the
> same MySQL server and it was easy (but perhaps not elegant) to just
> establish a separate connection using MySQLdb module.


You shouldn't have to do that.  Use this:

from django.db import connection, transaction
cursor = connection.cursor()

Then you can do anything you would with a MySQLdb cursor, e.g.:

cursor.execute("UPDATE foo SET bar = 3")

After any operation that changes data, apparently you should also call this:

transaction.commit_unless_managed()

I'm doing a lot of that right now to vastly speed up a huge data import.

Nick

-- 
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 Job Opportunity at IDLE GAMES (The Social Game Changers)

2011-02-23 Thread Nick Arnett
On Wed, Feb 23, 2011 at 12:35 PM, Aliciasf wrote:

...and (iv) the Tempting system...
>

That's the whole thing, isn't it?

;-)

Nick

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



Android mail? (Re: [tueysuezseftali:76683] [android-developers] Select mp3 to play?)

2011-02-17 Thread Nick Arnett
Anybody on django-users know why this mail is coming to our group?  It's
strange - the "To" header is android-developers, but the reply-to is
django-users.

I can't quite tell if it is a Google Groups problem or the person posting (
nikola1...@gmail.com).

Nick

On Thu, Feb 17, 2011 at 8:47 AM, vnv  wrote:

> Hi,
>
> I would like to enable my user to select mp3 or whatever sound file he
> want's to to play it as designated alarm sound.
>
> Is there any intent-alike thingy that I could call and user would
> browse selection and select, after which I could have path to the
> existing file.
>
> Tnx for help in advance.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-develop...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> --
> 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.
>
>

-- 
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 API efficient enough for filtering tens of millions of records?

2011-01-18 Thread Nick Arnett
On Tue, Jan 18, 2011 at 12:04 PM, Sithembewena Lloyd Dube  wrote:

> Hi all,
>
> I am building a search app. that will query an API. The app. will also
> store search terms in a very simple table structure.
>
> Big question: if the app. eventually hit 10 million searches and I was
> storing every single search term, would the table hold or would I run into
> issues?


As someone else said, 10 million records is no big deal for MySQL, in
principle.

However, you probably would do better to avoid all the overhead of a
database transaction for storing each of these.  I'm going to assume that
there will be duplicates, especially if you normalize the queries.  It would
make a lot more sense to log the queries into a text file, which has
extremely low overhead.  Then you'd periodically process the log files,
normalizing and eliminating duplicates, producing a bulk insert to load into
the database.  Bulk inserts will be FAR more efficient than using Django.

Nick

-- 
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: Full text indexing in small site

2010-12-26 Thread Nick Arnett
On Sun, Dec 26, 2010 at 11:06 AM, robos85  wrote:

> Hi,
> what engine fo fulltext indexing do you recommend? Small will be rather
> small, about 3000-4000 unique users per day. I need to index content of
> articles. It's avarage about 600-800 words.
>

If you are using MySQL, its indexing is probably sufficient.  You'll need to
store your text in a MyISAM table to do so.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Key 'buscar' not found in "

2010-11-25 Thread Nick Arnett
On Thu, Nov 25, 2010 at 6:35 AM, bvcelari  wrote:

> Hy,
> I'm trying to deploy my first django app, and I'm trying to use
> pagination , I 'm using Django 1.2
> I'm using a simple view with form, and with the request show the
> results paginated. when I try to go to next page
> the message appears:
> "Key 'buscar' not found in "
> buscar is a hidden value used for check if the request comes from the
> search form.
> I think this message comes from the "request" URL is not properly
> generated in fact my link targets to
> "http://localhost:8000/search/?page=2;
> instead of something like this:
> "http://localhost:8000/search/?option_value1=7_value2=3=2;
> There is any way to maintain the searchred url and indicate wich is
> the next page?


You need to pass that variable to the template, then add it to the page it
as a hidden input.

For example:



Nick

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



MySQL locking problem

2010-10-14 Thread Nick Arnett
I am having a problem with locking on MySQL and can't quite figure out
what's causing it.  Although I have some scripts that do raw SQL, none of
them are running, I see no other transactions in the process list, yet when
I call save() on one of my objects, the transaction locks, seemingly
forever.  Although most of my database tables are InnoDB, the one that I'm
seeing this happen on is MyISAM (because I'm using full-text indexing on
it).  So the table is getting locked somehow, but I sure can't see how, when
there is nothing else in the processlist.

mysql> show processlist;
+-+-+-+---+-+--++--+
| Id  | User  | Host| db| Command | Time
| State  | Info
|
+-+-+-+---+-+--++--+
| 2755442 | narnett | localhost   | narnett_clar2 | Query   |0 |
NULL   | show processlist
  |
| 2764186 | narnett | localhost:54940 | narnett_clar2 | Query   |  547 |
Locked | UPDATE `fm_posting` SET `author_id` = 5860, `posted` = '2009-09-28
00:00:00', `body` = 'This is the  |
+-+-+-+---+-+--++--+

Anybody have suggestions for tracking this down?

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 is the best way to implement time-based / cronjob actions in a Django app?

2010-10-13 Thread Nick Arnett
On Wed, Oct 13, 2010 at 4:38 AM, Mattias Linnap  wrote:

> Hi Django users,
>
> I'm building an application with Django, and I need some database
> changes to occur at certain times in the future - independently of any
> web request. Things like cleaning up expired sessions, deleting
> expired user actions, etc.


I use cron to do those kinds of things.   The scripts start with this:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
from my_project.models import *

And then they have access to whatever I need.  Actually, instead of
importing *, I usually just import the models I need for that script.

I like keeping all that housekeeping stuff separate from the web app.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Escaping text for raw SQL?

2010-10-12 Thread Nick Arnett
On Tue, Oct 12, 2010 at 9:53 AM, Steve Holden  wrote:

> ...
> but I can't off-hand remember which ones. If the back-end doesn't allow
> that then you have little option but to generate your own SQL. The
> required escape function is extremely simple:
>
>  def sqlesc(s):
>  return replace("'", "''")


Am I going brain dead, or isn't there more than just quotation marks that
need to be replaced?

This code is a back-end processing script, so there is no danger of SQL
injection by anybody (except me).

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Escaping text for raw SQL?

2010-10-12 Thread Nick Arnett
On Tue, Oct 12, 2010 at 9:00 AM, Javier Guerra Giraldez
<jav...@guerrag.com>wrote:

> On Tue, Oct 12, 2010 at 10:46 AM, Nick Arnett <nick.arn...@gmail.com>
> wrote:
> > Anybody know a good way to do this?
>
> Words.objects.filter(foo__in=mylist)


Didn't even occur to me to not use raw SQL for this, but I could... trouble
is, I wanted this to be reusable in a way that will be clumsy in the ORM.
 But maybe I'll go that route.  I'm using raw SQL for a lot of this because
the ORM is way too slow for what I'm doing.

Nick

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



Escaping text for raw SQL?

2010-10-12 Thread Nick Arnett
I can't figure out if there is a way to escape text for raw SQL queries.  I
can't use substitution (I think) because I'm building a query like this:

SELECT foo, bar FROM proj_words WHERE foo IN ("bat", "bug", "snip", "snap")

The list of terms for the IN operator can be quite long... I suppose I could
dynamically generate this:

SELECT foo, bar FROM proj_words WHERE foo IN (%s, %s, %s, %s)

... but I was hoping for the much simpler list comprehension that MySQLdb
would do:

my_list = [connection.escape(x) for x in my_list]

However, I don't see an escape function exposed in Django.

Anybody know a good way to do this?

TIA,

Nick

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

2010-10-01 Thread Nick Arnett
On Fri, Oct 1, 2010 at 3:52 AM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

>
>
> On Fri, Oct 1, 2010 at 3:35 AM, Steve Holden <holden...@gmail.com> wrote:
>
>> On 9/30/2010 8:26 PM, Nick Arnett wrote:
>> > Brain is mush, though.
>>
>>
> Thank you. I'm waiting with hope :)
>

Brain less mushy now...  Sometimes just knowing something is possible helps,
which was why I posted last night.

I used this idea:

http://www.mercurytide.co.uk/news/article/django-full-text-search/

and added a parameter to turn boolean on and off.

However, I'll add that I didn't much care for the results when not using
boolean.

Nick

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

2010-09-30 Thread Nick Arnett
On Thu, Sep 30, 2010 at 8:34 AM, Alessandro Ronchi <
alessandro.ron...@soasi.com> wrote:

> Is there any way to make a FULL TEXT search not in BOOLEAN MODE?
> I've found only
> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#search
>
> It says it uses BOOLEAN MODE as a default, but doesn't tell how to
> avoid default..
>

Um, I hate to do this, but for the moment, I'm going to tell you "yes" - but
I can't remember how right now.  Been awake for 30 hours and waiting for a
plane to take me home!  Did a demo today for a big client, involving
Django/MySQL full text and parametric search and they loved it... so it's on
my mind.  If you don't get a real answer by tomorrow afternoon, I may be
conscious again then.  You have to use one of the alternative approaches to
search, as I recall.  Brain is mush, though.

Nick

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

2010-09-24 Thread Nick Arnett
I was tackling this problem recently and found several approaches by
searching for Django login form.  I ended up using a middleware solution
that brings up a login page no matter where the user tries to go, then
redirects them to the page they were trying to view... but that only makes
sense if your users aren't allowed to see any page without logging in.

See
http://www.mail-archive.com/django-develop...@googlegroups.com/msg06473.html


Nick

On Fri, Sep 24, 2010 at 8:23 AM, Tran Cao Thai
wrote:

> Hello all,
>
> I have a login form that should appear in every pages of the site. How can
> i create it from the views file ? Since every form is triggered by calling a
> function in the views file, do i have to create the form in every function?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: manage.py syncdb not working

2010-08-24 Thread Nick Arnett
On Tue, Aug 24, 2010 at 7:43 AM, Sithembewena Lloyd Dube
wrote:

> Thanks Reinout. I have been seeing a lot of discussions regarding South
> lately - time to dive in and find out what it is and what it means for me.
>
> I was under the impression that Django would add a field to my table. So,
> is syncdb only good during initial database setup?


That is essentially correct, though I have modified tables by renaming the
old one, letting syncdb recreate it, then copy the old data into the new
table.  However, due to foreign keys, that's not as simple as it might
sound.  Early in development, I have also let syncdb create a whole new
database, then copied the old data into it.

Come to think of it, I have also sometimes created a modified table under a
temporary name, so that I can see what Django would have done if it were a
new setup, so that I can modify the old table manually to match how Django
would have done it automatically (and then drop the temporary table).

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: I did something wrong while registered

2010-08-09 Thread Nick Arnett
On Mon, Aug 9, 2010 at 1:50 PM, John Fabiani  wrote:

> Hi,
> I recently registered for the group and I must have done something wrong
> because I am receiving every posting twice (duplicates).  Can someone fix
> the
> problem or direct me to where I can fix it.
>
>
Have you looked at the headers of a pair of messages to see if you are
receiving them on different email addresses?  If so, just unsubscribe with
one of them.  If not, well, you need further help!

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Querying in a loop - cached results?

2010-08-08 Thread Nick Arnett
On Sun, Aug 8, 2010 at 3:09 PM, Karen Tracey  wrote:

>
> Probably you are seeing the effects of the default transaction isolation
>> level on MySQL/InnoDB, which is "repeatable read". See
>> http://groups.google.com/group/django-users/browse_thread/thread/e25cec400598c06dfor
>>  more explanation.
>
>
Ah, I didn't think of that.  Didn't even think about the fact that there are
transactions going on behind the curtain.  I'll look into that.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Querying in a loop - cached results?

2010-08-08 Thread Nick Arnett
On Sun, Aug 8, 2010 at 11:52 AM, Daniel Roseman wrote:

>
>
> Where is this query running - in a view, or an external script? And
> how is the data being added to the db?


In both cases -- adding data and analyzing -- it is an external script,
using the Django ORM.

Nick

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



Querying in a loop - cached results?

2010-08-08 Thread Nick Arnett
I'm having a problem that I can't figure out from reading the docs.  I have
a loop that runs the same query every five minutes, to see if there is new
data to process.  However, it doesn't return the new data the second and
subsequent times it loops.  It's something like this:

while 1:
 data = Foo.objects.filter(not_analyzed=True)
 if len(data):
  for item in data:
   do_analysis(item)
 sleep(300)

Even though I know there is new data added while it is sleeping, the query
doesn't return it.  If I kill the process and re-start, it finds the new
data, so it smells like a caching problem... but I don't see anything in the
documentation that would suggest this.  It shouldn't be the database query
cache (MySQL) because it should know the data has changed.

I've tried adding "del data" at the bottom of the loop, but that didn't help
- thought maybe if I explicitly deleted the data, that would work.

Any ideas what's going on or how to solve this?

TIA,

Nick

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

2010-08-03 Thread Nick Arnett
On Sun, Jul 18, 2010 at 10:19 AM, Biju Varghese wrote:

> Eclipse is the best IDE for python and django.
>
>
I don't know if it is actually the best, but I'm happy with it.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
On Mon, Aug 2, 2010 at 9:39 AM, Antoni Aloy  wrote:

> My first thought would be to backup the database, then put the project
> under South control. Then create a one-to-one relation between models
> and the possible create a upgrade script.
> Then, if necessary, you could create properties in the original model
> to map the names you have in your application.


Interesting idea... anybody here ever tried anything like that?

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
On Mon, Aug 2, 2010 at 2:34 PM, Steve Holden  wrote:

>
> Another alternative would be to create a view of the joined tables using
> SQL CREATE VIEW, then treat the view as a table in Django. You do have
> to be careful that the view should be updatable, though.


Ah... I didn't think of views.  Haven't used them in a while, but that's
worth a shot, I think, since that way, I might not have to touch the Django
code at all.

Nick

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



Splitting LONGTEXT column to its own table?

2010-08-02 Thread Nick Arnett
I'm thinking that I could get a pretty good performance improvement on a
couple of tables by moving their LONGTEXT columns into their own tables.
Just wondering if there's anybody here who has done something like that - is
there a way to do this transparently to Django, so I don't have to re-write
every piece of code that uses those tables.

In other words, I'm looking at vertical partitioning, but only across
tables, not databases, as transparently as possible to the code that I've
already written.

Thanks in advance for any pointers.

Nick

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

2010-07-19 Thread Nick Arnett
On Mon, Jul 19, 2010 at 10:01 AM, Tereno  wrote:

> Web Faction does look like an interesting option. However, looking at
> the memory specs, how would I be able to tell if it's sufficient for
> at least 2 Django applications? For example, if I got with Shared 1, I
> get 80MB (180MB VPS) - I'm assuming that's not going to be enough
> right? Of course it does depend on the application itself but in
> general, do you reckon it can support 2 Django apps?


The only honest answer is "it depends."  But the good news about Webfaction,
which I've been using for about six months, is that you can start with the
cheapest option and then upgrade at any time.  And downgrade.  They make it
easy.

You'll get warnings from them immediately if you exceed the allocated
memory.

I was able to run a database-intensive app under Shared 1 for a long time.
It was only when I started doing some heavier analysis that I had to bump up
to Shared 2.

Nick

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



Price fixing (was Re: How much would you charge for this? £5k? £15k? £50k?)

2010-06-21 Thread Nick Arnett
On Mon, Jun 21, 2010 at 2:12 AM, ALJ  wrote:

> I'm just starting out with Django so using an hourly rate isn't really
> applicable because I'm going to be much slower that a 'real'
> developer. So far I've spent about 6 months part time.
>
> What kind of ballpark amounts would people suggest this is worth?


I don't know about the law elsewhere, but in the United States, having a
discussion with other vendors on what to charge clients opens you up to
prosecution for price fixing.  It almost certainly should be a banned topic
here.

For a fairly good description of the issue, look at the HTML Writer's Guild
guidelines:

http://www.hwg.org/resources/faqs/priceFAQ.html

Nick

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

2010-06-19 Thread Nick Arnett
On Sat, Jun 19, 2010 at 9:21 AM, zweb  wrote:

>
> (Mysql text search will not work as I use INNODB. Solr is powerful but
> I heard it is very memory hungry and it is in Java. Whoosh is not yet
> as mature as others. So that leaves choice between Django Sphinx and
> Haystack Xapian.)


I meant to mention that although I'm using InnoDB, I'm storing a copy of the
searchable text in a MyISAM table and using the MySQL search on it.  That's
okay for now, but I'm looking for clustering, faceted search and other fancy
stuff.

I've worked in search-related technology for a long time and I should know
that search performance always demands lots of memory...  So I may bite the
bullet and use Solr, after all.  I just wish there were a way to trade off
the memory for speed until I'm ready to deploy a real working version.

Nick

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

2010-06-19 Thread Nick Arnett
On Sat, Jun 19, 2010 at 9:21 AM, zweb  wrote:

> I need to implement search solution over models in mysql.
>
> Anyone has experience with both or has gone through same decision
> making?
>
> What should I consider before choosing one or other?


I'm making a similar decision... as far as I can see, neither one does
search result clustering, which I'd like.  But the memory required to host
Solr means a big increase in hosting costs.  I'm using Webfaction, so to go
from their basic service to the one that offers 300 MB of memory is an
increase of about $25/month, which I'd rather not have to pay yet.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it safe to alter Django generated tables in MySQL to have composite PK?

2010-05-02 Thread Nick Arnett
On Sat, May 1, 2010 at 11:13 AM, Continuation <selforgani...@gmail.com>wrote:

>
> On Apr 30, 9:42 pm, Nick Arnett <nick.arn...@gmail.com> wrote:
>
> > If you don't have data in the table, just drop it and use
> "unique_together"
> > in models.py to define your composite key.  You'll find that in the
> Django
> > docs.  Then do syncdb and Django will create the table with your
> composite
> > key.
>
> I don't have data.
>
> Using "unique_together" wouldn't work because I want that composite
> index to be the clustered index. It'd only be the clustered index if
> it is the primary index.
>

Oh, I see now.  I often forget that Django always creates its own PK with
the id.

It should be no problem to make the Django id a unique key and the composite
key from unique_together the primary key.  I can't think of any functional
way in which they are different.  But you are right, you will have to do
this manually after syncdb.  You would still define the composite index with
unique_together, so that Django knows about it.

Just make sure you make the id column, the one that Django expects to be the
primary key, a unique index.

Although I can't think of any reason this wouldn't work, I haven't actually
tried it.  A little voice is whispering that it might affect foreign keys,
but I think they only require indexes, I don't think they have to be primary
keys.  And I think you will have to do this before you add any data, or else
the FKs will make it much harder.

Nick

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Is it safe to alter Django generated tables in MySQL to have composite PK?

2010-04-30 Thread Nick Arnett
On Wed, Apr 28, 2010 at 8:09 PM, Continuation wrote:

> I'm using MySQL with Django.
>
> MySQL uses clustered index. I have a class AuctionBid for which the
> "natural" PK is (user_id, auction_id).
>
> I'd like to set (user_id, aucton_id) as the PK so that it'll be the
> clustered index. I understand that Django doesn't support composite
> PK. But what if after syncdb I just ALTER TABLE to make (user_id,
> aucton_id) the PK. Would that work with Django or would that introduce
> some unwanted behavior under the hood?


If you don't have data in the table, just drop it and use "unique_together"
in models.py to define your composite key.  You'll find that in the Django
docs.  Then do syncdb and Django will create the table with your composite
key.

Otherwise, you can make the change in models.py, as above, and change the PK
manually.

If there are FKs involved, you might also want to make the appropriate
changes if you're not re-creating all the involved tables with syncdb.

One other route, if you have data, is to rename the existing tables (can be
tricky with FKs), then syncdb and then copy your data... or, even easier,
create a whole new database with syncdb and copy your data into it.

Nick

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



Encoding makes text go away in templating; mx.DateTools.strptime v. utf-8

2010-04-30 Thread Nick Arnett
I'm stuck on a problem with encoding (or possibly decoding).

I'm extracting dates from web pages with regular expressions.  Now I want to
parse those dates into Python date objects.  Generally speaking, this is no
big deal.  It takes some effort because I'm dealing with a number of
different date formats, but I expected that.

I'm using mx.DateTime.strptime to parse the datetimes out of the strings
that I've captured with regexes.  That works fine much of the time.  It
fails when the string is utf-8 and there are characters that can't be
converted (a familiar problem).

The weird thing is that when I decode the original date string to latin-1,
Django seems to eat the entire string that I build out of that date.
Perhaps I should clarify.  I have a web page that shows me what text was
captured by the regex (so I can see that it is getting the correct chunk)
and it also shows me the output of strptime (using the pattern string for
the relevant date format).

So... when I display the parsed data via Django, there's nothing there.  But
when I add a character count for what my views.py script is sending to the
template, it shows that there is plenty of text there.  Somewhere in the
templating, that text is getting lost - it doesn't show up at all in on the
resulting page.  I know that my code is producing text because I can run it
stand-alone and see the generated text.

I don't quite even know how to figure out where it is disappearing... but
I'm hoping somebody here has seen something similar - vanishing string after
encoding...?

Thanks in advance for any insights.

Nick

P.S. As often happens, describing the problem helped a bit... it seems to be
related to mixing unicode and non-unicode strings.  When I decode the
results to utf-8, my text is back but I still can't get strptime to work
on these strings, even after decoding to latin-1, which I thought might do
it.  So frustrating that it looks like plain ascii on the page, but I can't
get it to behave like plain ascii!

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

2010-04-22 Thread Nick Arnett
On Thu, Apr 22, 2010 at 6:45 AM, thanos  wrote:
>
>
>
> Finally just recently SEC announced that they might require regulatory
> files to be submitted in Python and not in legal English.
> Their rational is that Python is less ambigious and the English and
> more clean, readable  and structured than XML. (http://www.sec.gov/
> rules/proposed/2010/33-9117.pdf
> ).
>
>
I couldn't quite believe that when I read it, but there it is, right on the
SEC web site.  And not dated April 1st, either.

And for those who don't want to download the link, Python would just be used
to define formulas; the idea is that investors could run the code rather
than having to implement algorithms from a text description.

Any idea why they chose Python?  I imagine it is because it is compact and
easy to read, but I'd be curious what attracted them.

There's a snake oil joke in there somewhere.

Nick

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

2010-04-01 Thread Nick Arnett
On Wed, Mar 31, 2010 at 8:13 AM, Wiiboy  wrote:

> Hi guys,
> I've gotten two emails from "Mail Delivery Subsystem
> " with the subject "Your message was NOT
> received by django-us...@googlegroups.com!".
> The body is below.  Anyone know why I'm getting these?  Is anyone else
> getting them?  I have no affiliation with Dreamhost or at all, so this
> is...strange


Yes, I think everybody who posts is getting one each time they post.
There's an address subscribed to the list at deamhost... and apparently it's
not easy to identify.  I've had this kind of small nightmare when
administering a mailing list... the better mailing list manager apps have an
extra header to show whose subscription is guilty, since this is
occasionally hard to track down.  I'm guessing that in Google Groups, it is
not so obvious.  Dreamhost is being bad and not including the headers from
the original message, or it would be obvious which subscription is causing
it.

And now I'll get another one.

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: using "id" as a field name in ModelForm.

2010-04-01 Thread Nick Arnett
On Thu, Apr 1, 2010 at 10:34 AM, Chris Curvey  wrote:

>
> class FoobarForm(ModelForm):
>  foo = forms.FloatField(label = '$')
>  id = forms.HiddenField()


If you're using newforms, there's no such thing as HiddenField.

Perhaps you want this:

id = forms.IntegerField(widget = forms.HiddenInput)

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: form object has no attribute 'cleaned_data'

2010-03-31 Thread Nick Arnett
On Wed, Mar 31, 2010 at 9:09 PM, jeff  wrote:

>
>page_title='Add a Pair'
>if request.method == 'POST':
>form=SymForm(request.POST)
>if form.is_valid:


is_valid is a call - you want this:

if form.is_valid():

Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: "Illegal mix of collations": how to handle that?

2010-02-27 Thread Nick Arnett
On Sat, Feb 27, 2010 at 4:06 AM, jul  wrote:

> hi,
>
> when submitting some characters in a charfield of a django form I get
> the following error (e.g. when submitting 'ś')
>
> (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and
> (utf8_general_ci,COERCIBLE) for operation '='")
>
> It seems that the character I'm submitting is not part of my database
> character set. How can I handle that? Should I first check in the
> clean function of the field whether all characters are included in my
> database charset ? Is this not handled by django (I would expect some
> error before submitting the data to the database)?


You probably need to fix this in your database, which I'm guessing is
MySQL.  Change all your tables and columns to UTF8 and this should
disappear.  Solving it on the Python side will probably drive you crazy.
Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Project optimisation stage: Advice to boost speed of database queries across tables?

2009-12-30 Thread Nick Arnett
On Wed, Dec 30, 2009 at 7:15 AM, Adam Playford wrote:

> I'm not an expert on this, but a few thoughts.
>
> First, if I'm reading your message right, it sounds like your problem
> probably isn't with the query, but with how many times you're running
> it.


I'll echo that... the problem is not the database - the queries are as good
as it gets.  The problem is running them repeatedly.

If all else fails, I'd replace those queries that execute 500 times with raw
SQL that uses the IN operator to get the required rows.

E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
`common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173)

I imagine there's an ORM query that will do the same thing, but I know MySQL
far better than I know Django.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: access legacy data without model.py

2009-12-13 Thread Nick Arnett
On Sat, Dec 12, 2009 at 7:24 AM, dundeemt  wrote:

> I need to access data in other databases.  I don't want them listed in
> model.py as I won't be using django's orm for them. Given this, where
> is the preferred place to put the db connection for this data?  The
> only references I could find show creating a db connection in the
> view, http://www.djangobook.com/en/beta/chapter05/  -- while valid for
> my purposes, is there a better place to cache the connection?
>
> Also, I will be accessing 7+ other databases of varying types, some
> have hundreds of tables and I have no desire to create a model when
> for them when I only need to get to a few values.  I will not be
> updating data in these other databases, only doing lookups.  So I am
> not interested in making a proper django data connection to them.


I think that good design practice would be to create a data access module
for this purpose and import it when you need it.  I've done this a few times
for MySQL access and even wrapped some of the more frequent patterns and
queries into methods in that module.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Can I change the models.py of an existing django app?

2009-12-11 Thread Nick Arnett
On Fri, Dec 11, 2009 at 11:36 AM, Zeynel  wrote:

>
>
> So, it seems that, according to documentation, syncdb will create the
> new tables?


Yes, it will create *new* tables.  It will not alter existing tables.

If you don't need to save your existing data, the easiest thing is to drop
the old database and re-create it, then let syncdb create all the tables
again.

If you do need to save old data, you could either add the columns yourself
or rename the existing table, use syncdb to create the new version, then do
something like INSERT INTO foo (id, bar, bat) SELECT id, bar, bat FROM
old_foo.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Could Django model dynamically create new class with new table?

2009-12-09 Thread Nick Arnett
On Wed, Dec 9, 2009 at 11:18 AM, HUANG Dong  wrote:

> Thank you, Bruno.  Your answer is really helpful and covered another
> issue I hadn't noticed yet.  But my question may be related to
> different topic.  In my example, number of "libraries" is unknown in
> develop time, neither does the classification of "books".


I suspect you could use a raw SQL command - "ADD PARTITION" - in MySQL to
create a partition for each new library and/or classification.  Then the
database would take care of everything else (assuming that the library or
classification is a column on which you define the partitioning), which
would be a Good Thing (because this really doesn't belong at the application
level if at all possible).

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: delete every record in a table?

2009-12-04 Thread Nick Arnett
On Fri, Dec 4, 2009 at 12:56 PM, Christophe Pettus  wrote:

>
> On Dec 4, 2009, at 12:37 PM, Phlip wrote:
>
> > could such a method
> > call only send one SQL command?
>
> If you are using PostgreSQL as a back-end, it has a very efficient
> command TRUNCATE for just such a purpose, which you could sending as a
> raw SQL command:


Same works for MySQL.  And it is far, far faster than most other ways, for
large tables.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Forms - readonly representation?

2009-12-03 Thread Nick Arnett
On Thu, Dec 3, 2009 at 2:50 PM, Todd Blanchard  wrote:

> I'd gotten nearly a dozen responses to a later question so I figured the
> threshold of awareness had passed on this one.


Never assume correlation implies causation... ;-)

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Forms - readonly representation?

2009-12-03 Thread Nick Arnett
On Thu, Dec 3, 2009 at 9:05 AM, Todd Blanchard  wrote:

> Forms seem nifty, but sometimes I want to display the data in the same
> format but readonly.  Is there a to do this?  I can't seem to find it.


I found this gizmo for doing that sort of thing:

class ShowOnly(forms.Widget):
"""
Show only the data do NOT have a input field
"""
input_type = 'hidden'

def render(self, name, value, attrs=None):
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
if value is None: value = ''
final_attrs = self.build_attrs(attrs, type=self.input_type,
name=name)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
value = force_unicode(value)
final_attrs['value'] = force_unicode(value)
return mark_safe(u'%s' %
(forms.util.flatatt(final_attrs),value))

I found it here:

http://www.djangosnippets.org/snippets/1185/

Nick
(tempted not to respond due to the "deafening silence" comment... did you
imagine you're due an instant answer?)

--

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

2009-12-02 Thread Nick Arnett
On Wed, Dec 2, 2009 at 6:08 PM, Jeffrey Taggarty wrote:

> Hi guys, thanks for responding. I didn't want to have to create 2
> entries in the database for a friendship because of the obvious
> integrity issues such as friendship deleting and friendship
> relationships to files etc seems like a lot of unnecessary
> duplication. I didn't see that symmetrical m2m before, thanks a lot
> for the link. I am going to refactor my code and schema armed with
> this information.
>

I was thinking that perhaps if you'd like to learn more about approaches to
what you're doing, you could look up things that have been written about
storing directed acyclical graphs in relational databases.  That's
essentially what you're doing.  You may even conclude that a relational
database isn't the right data store... but that's what Django was built for,
of course.

If you want to scale, really scale, you'll want to use a graph library.
There are several for Python, including NetworkX, which I've used, and
Boost, which I haven't.

Probably more info than you wanted, but there it is.

Nick

--

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

2009-12-02 Thread Nick Arnett
On Wed, Dec 2, 2009 at 2:04 PM, Jeffrey Taggarty wrote:

> Hi,
> I am having difficulties with listing this type of data. Scenario is
> as follows:
>
> 1) user1 add's a friend called user2
> 2) user2 confirms that user1 is his friend
>
> what should happen is user2 and user1 see's each others name in their
> friends list. What's happening now is I am able to add user2 to user1
> friends list but user1 cannot see user2 in his/her list. My question
> is how do I get user1 to show up in user2's list and user2 to show up
> in user1's friend list if a user has confirmed friendship? I was
> thinking of utilizing the confirmation status in the model and because
> that user1 and user2's id is both in the confirmed relationship I
> don't see any integrity issues here. Any tips?


You haven't done anything to express the reverse relationship, if I
understand all this correctly, so of course it doesn't show up.  A
straightforward way to solve that would be to simply add the reverse entry
at the same time you add the initial entry, since you are assuming the
friendship is bidirectional.  In other words, at some point when you save a
form, you're creating a row like this:

rel = Friendship.objects.create(to_friend=user1, from_friend=user2)
rel.save()

But are you doing the reverse?

rel = Friendship.objects.create(to_friend=user2, from_friend=user1)
rel.save()

There are other ways to accomplish it, but I think this is the simplest.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ModelMultipleChoiceField with checkboxes: How to generate the HTML "checked" option?

2009-11-29 Thread Nick Arnett
On Sun, Nov 29, 2009 at 8:30 PM, Gloria  wrote:

> Here's the line from my model:
> class UserProfile(models.Model):
>some other fields...
>privacy_options = models.ManyToManyField(PrivacyOption,
> blank=True, null=True, db_table = 'usr_privacy_selection')
>
> Here's the bit from my form:
>
> class ModifyProfileForm(forms.Form):
>some other fields...
>privacy = forms.ModelMultipleChoiceField(
>queryset=PrivacyOption.objects.all(),
>required=False,
>show_hidden_initial=True,
>widget=forms.CheckboxSelectMultiple,
>)
>

Hmmm... what are you trying to do by passing the queryset?  Doesn't that
send your form everybody's data, instead of just the active user?  If I
recall correctly, passing a queryset will initialize a form, so perhaps all
you need to do there is make it a "get" that returns only the current user's
data?



> When I initialize it like this:
>
>data = {some other fields...
>'privacy' : user_profile.privacy_options
>}
>
>form=ModifyProfileForm(data)
>

That doesn't look right.  I think should be:

 form=ModifyProfileForm(initial=data)

But I'm also not sure if your data dict is correct.  It should have an item
for each field that you want to initialize.

>
> Trying to set the initial value for this particular field also does
> not seem to help:
>
>initial_dict = {}
>for x in user_profile.privacy_options.all():
>initial_dict[x.name]=True
>
>form=ModifyProfileForm(data)
>form.fields['privacy'].initial = initial_dict
>
>
Again, I don't quite understand why your queryset is using "all" - seems
like you would just want one row ("get").  I'm not sure what the form object
would do with a queryset that has multiple rows.  Your dict should be passed
in the second to last line:

form=ModifyProfileForm(initial=initial_dict)

Something like your last line might work, but it is a lot more work than
just passing the form the initialization dict.

Others feel free to jump in here and set me straight as needed.  I'm still
fairly new to Django, so I'm no expert... but I've been struggling to learn
the same stuff lately.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: how to get remote port number

2009-11-29 Thread Nick Arnett
On Sun, Nov 29, 2009 at 4:01 PM, Steve Holden  wrote:

>
>
>> Not at all. The client will typically use an "ephemeral"  port (one it
> obtains by saying to its local TCP layer "gimme a port number, I don't care
> what it is"). The connection (any connection) has *two* endpoints, and the
> port numbers each system uses are up to that system.
>
> Obviously you want the server to listen on a "well-known" port most of the
> time, though as you have observed the Django administrator can configure the
> server to listen on any desired port. But the client really doesn't care -
> it just expects the server to reply to the same port number it sent its
> request from.
>

Of course, but I can't imagine why anybody would ever worry about that at
the application level.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: how to get remote port number

2009-11-29 Thread Nick Arnett
On Sun, Nov 29, 2009 at 2:24 PM, The New Hanoian wrote:

> Hi,
>
> I'm learning Django. In the tutorial i find that the client IP address
> can be retrieve through HttpRequest.META["REMOTE_ADDR"]. But I
> couldn't find a way to retrieve the client port number. I think it
> should be obvious. Am I missing something?


Um, yes.  You're missing the fact that you already have it, since you are
the one who configures Django's port.  The client can only contact you on
the port it is running on, of course.

In other words, the client port number always is the same as the server port
number.  Gotta be so.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ModelMultipleChoiceField with checkboxes: How to generate the HTML "checked" option?

2009-11-29 Thread Nick Arnett
On Sun, Nov 29, 2009 at 9:52 AM, Gloria  wrote:

> Thanks for the response. I am trying to do this on the server side.
> Here is more detail.
> I am initializing it to all unchecked checkboxes in my forms.py.
> Then, in my view, I am trying to have HTML generate a "checked" value
> for certain checkboxes, based on some user data I received in that
> view.
> How do I generate "checked" HTML option using the builtin
> ModelMultipleChoiceField for certain checkboxes? Is there a builtin
> option that I  should set manually to cause the "checked" option to be
> generated? Or do I have to iterate over these fields, match them with
> data I have received, and generate the "checked" option myself, in the
> template?
>
>
You shouldn't have to do that if the data is available in your view.  It
should be as easy as passing a dict as "initial" to your form instance you
create in the view:

form = MyForm(initial = {"foo"=True, "bar"=True}

with the field names (instead of foo and bar) of the check boxes you want
checked.  Your form then should have them checked when it is rendered.

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ModelMultipleChoiceField with checkboxes: How to generate the HTML "checked" option?

2009-11-29 Thread Nick Arnett
On Sat, Nov 28, 2009 at 3:05 PM, Gloria  wrote:

> Hi all,
> I've spent way too much time getting trying to get this widget to work
> the way I am envisioning.
> In the forms, I want to initialize it, but in the view I need to
> determine which boxes are checked.
> Has anyone done this without writing their own widget? It would be
> great to know how.
> Thank you in advance,
>

Rather than trying to do that on the client side (which is what I think
you're saying), have you considered just passing the required values to the
template as context variables?

Nick

--

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

2009-11-28 Thread Nick Arnett
On Sat, Nov 28, 2009 at 3:21 PM, Mikey3D  wrote:

> Windows 7:
>
> My project is in: C:\Python26\Lib\site-packages\mysite
>
> I'm working on this section: Playing with the API
> http://docs.djangoproject.com/en/dev/intro/tutorial01/#playing-with-the-api
>
> When I do (Windows+R >cmd >OK) to do python shell (python manage.py
> shell) it works. But I have try other tool that come with Python26 is
> IDLE (Python GUI) and I get an error:


I think what you need is the following before you import anything from
Django: (or any module that imports from Django):

import os
os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

(The absolute or relative path to your settings file.)

Nick

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: is_valid error/bug when unique_together fields are both ForeignKey fields

2009-11-26 Thread Nick Arnett
On Thu, Nov 26, 2009 at 9:37 AM, cerberos  wrote:

> I have a model that has two fields (Django 1.1.1)
>
> class FooBar(models.Model):
>foo = models.ForeignKey('Foo')
>bar = models.ForeignKey('Bar')
>
>class Meta:
>unique_together = (('foo','bar'),)
>
> When is_valid is called in my view and the combination of fields
> already exists (eg unique_together is false) the error returned is
> "Foo bar with this None and None already exists."
>
> "None and None" seems like a bug to me, but I'm not sure.


I've seen that kind of error, too and found various references to it when I
searched.  In my case, the problem was an extraneous comma in the code,
which wasn't picked up as a syntax error... which bothers me.  Django seems
to fail to surface some syntax errors and either produces no results or some
other error.

What I think this generally means is that in your view, the object isn't
getting initialized for some reason.  I'm assuming that you get the error
when you try to save.  I'd carefully go over whatever initializes or sets
the data.

Nick

--

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

2009-11-26 Thread Nick Arnett
On Sat, Nov 21, 2009 at 7:09 AM, Carlos Ricardo Santos <
carlosricardosan...@gmail.com> wrote:

>
>
>>
>> Obviously I can't use that number in font-size (150pt is too big) and
>> I have to make a proportion (150 -> 20pt, 1 -> 5pt, 50 ~>10pt and so
>> on).
>>
>> How can I accomplish that?
>>
>>
What you need is called data normalization - fitting data to a desired scale
- in statistics and analysis.

Here's a general page about normalization:

http://www.qsarworld.com/qsar-statistics-normalization.php

I'd imagine that there's a Python library or module that will do this for
you, but it's not hard to write your own.

Nick

--

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




Can't get form to update, rather than insert

2009-11-23 Thread Nick Arnett
I have a form that I've tried creating a couple of ways, including as a
ModelForm, which doesn't seem to want to perform an UPDATE operation.  I'm
hoping for some help here... If I create it as a ModelForm, it doesn't
validate, I'm guessing because the form doesn't include the foreign keys in
the model (I haven't tried passing them in the form - that shouldn't be
necessary - but I probably will, next).  If I create a form from the POST
data, it complains that required fields are missing.

My reading of the docs is that if I supply the primary key and the row
exists, an UPDATE should happen, which won't care if required fields are
present or not (since I don't want to change those values).  But that's not
happening - no matter what I do, it seems to be generating an error that
indicates it is trying to create a new row with a duplicate ID.

Anybody have a working example of a form that updates, rather than inserts?
Oh, and forcing an update in the save method doesn't solve the problem.

I have no problem performing updates outside of the context of forms - I
just can't figure out how to get it to work with forms.

Thanks in advance,

Nick

--

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




Strange debugger behavior

2009-11-19 Thread Nick Arnett
I'm not sure if this is a bug... couldn't find anything quite like it in the
tracker.  I'm using Komodo as my IDE.  When I step through source, the
filters in a Model.objects.filter method are ignored.  Instead of getting
the handful of rows that I want from my database, Django (1.1) grabs the
entire table -- there's no WHERE clause in the SQL it executes (this is with
MySQL).  When I run it outside the debugger, or avoid stepping into the
"magic" parts of the database stuff, it behaves properly - the WHERE clause
is present.

For an awful moment, I thought it was trying to cache the entire table...

This makes debugging with Komodo somewhat challenging, since the table where
I first encountered this has 50,000 rows that include the full text of web
pages.  Lots of data and even with plenty of memory, my machine starts
thrashing horribly when this happens.

Anybody aware of this as a known issue?  Any fix?

Since I can avoid it by not stepping through the "magic" parts of the
database stuff, it isn't critical.

Nick

--

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




Re: Set model form initial value?

2009-11-18 Thread Nick Arnett
On Wed, Nov 18, 2009 at 2:01 AM, Ilya Polosuhin wrote:

> Just use "initial" keyword on creation form
> class myForm(forms.Form):
> test = forms.CharField(label = _('test'), max_length=255, required =
> True)
> 
> myForm(initial = {'test': 'test string'}).
>
> If you use form that generated from model:
> class myForm(forms.Form):
>
>   class Meta:
> model = myModel
> ...
> myForm(initial = myModel(var1 = 'qq' ))
>

Ah, that last way of doing it is the one that I couldn't find.

Meanwhile, I kludged it by using a loop to generate the choices and "ifequal
choice.id selected_project"  to insert the "checked" attribute into the
appropriate choice, which works.

Nice to know the right way, however.  Thanks

Nick

--

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




Set model form initial value?

2009-11-17 Thread Nick Arnett
I can't see to figure out how to do something fairly simple - set the
initial value of a model form field at runtime.  The form is a simple set of
radio buttons that lets the user choose which project to work on.  I'm
storing the selection in a session variable and that's working fine.  What I
can't figure out, though it seems like it must be staring me in the face, is
how to set the current choice that's stored in the session variable, so that
when the form is displayed, the current project's radio button is selected.

I've created custom forms and set initial values... but how do I do that
with a model form?  Or should it be a custom form to do that?

Thanks in advance,

Nick

--

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




Re: MySQL error subquery returns more than 1 row

2009-11-17 Thread Nick Arnett
On Tue, Nov 17, 2009 at 9:03 AM, Ilya Polosuhin wrote:

> I don't fully understood your question. Of course I have more than one row
> at test_mymodel2
> SQL query was formed by django-ORM. I just call
> print (MyModel.objects.filter(key_to_mymodel2 =
> MyModel2.objects.all()))._as_sql())
> and write here output.
>

Ah, sorry - I was confused... I thought you wrote the SQL yourself.  That
does seem to be a problem with the ORM.

Nick

--

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




Re: MySQL error subquery returns more than 1 row

2009-11-17 Thread Nick Arnett
On Tue, Nov 17, 2009 at 7:17 AM, Ilya  wrote:

> I just developed some code like:
>  MyModel.objects.filter(key_to_mymodel2 = MyModel2.objects.all()))
> This query produce SQL:
> SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id =(select `id`
> from `test_mymodel2`)
>
> It works fine on SQLLite, but in MySQL it produce error:
> OperationalError: (1242, 'Subquery returns more than 1 row')
> MySQL to work need query:
> SELECT * FROM `test_mymodel` WHERE key_to_mymodel2_id = ANY (select
> `id` from `test_mymodel2`)


With the same data?  It seems like a legitimate error unless test_mymodel2
has just one row, which would be odd.  I would expect the subquery to have a
WHERE or LIMIT clause that would restrict it to returning a single row, to
be useful.

If you really expect the subquery to return multiple rows, perhaps you mean
something like this:

SELECT * FROM `test_mymodel` t1, (SELECT `id` FROM `test_mymodel2`) t2 WHERE
t1.id = t2.id

Nick

--

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




Re: form with loop over fields?

2009-11-12 Thread Nick Arnett
On Wed, Nov 11, 2009 at 11:28 PM, andreas schmid wrote:

>
>
> ok this is fine for the form representation but how should i extend my
> model to define the field i am going to multiply 12 times a year for x
> years? (actually im using generic create_update view to get the form out
> of the model)
>
> and how should i store the values independently from each other?


I believe the simple way would be a model that has month and year fields,
with a meta method that defines them as unique together.

Nick

--

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




Re: form with loop over fields?

2009-11-11 Thread Nick Arnett
On Wed, Nov 11, 2009 at 6:48 AM, andreas schmid wrote:

>
> i would need something like:
>
> jan   feb   mar   apr   may
> 2007 [...]   [...]   [...]   [...][...]
> 2008 [...]   [...]   [...]   [...][...]
> 2008 [...]   [...]   [...]   [...][...]
>
> i dont think a formset would be the right way to go in this case (but
> maybe im wrong).
>
>
I think a formset is the right approach.  I'm working on something like this
right now.  One slightly tricky bit was to get the fields to be in rows
instead of one long column.  The solution looks like this in the template:

{% for field in form.visible_fields %}
{{ field }}
{% endfor %}

Now I'm trying to figure out how to get the "year" column data into the
form, dynamically from a model.

Nick

--~--~-~--~~~---~--~~
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: Where are forms usually defined?

2009-11-03 Thread Nick Arnett
On Tue, Nov 3, 2009 at 11:26 AM, f4nt  wrote:

>
> forms.py is pretty standard. You'd end up importing them in your
> views.py.


Thanks... that's what I was guessing.  But it appears to me that I sometimes
see ModelForms in models.py... wondering if that's typical.

Nick

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



Where are forms usually defined?

2009-11-03 Thread Nick Arnett
I find myself frequently frustrated by examples and tutorials that include
code snippets that don't identify where they live.  In particular, I haven't
quite figured out where forms usually are defined and then where they need
to be imported.

I see that forms sometimes are in a file called forms.py... but somewhere
I'd expect to then see an import statement along the lines of "from
mysite.forms import *".  If I use forms.py for my forms, where does that
file need to be imported?

Thanks,

Nick

--~--~-~--~~~---~--~~
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: Form that updates a list of items?

2009-11-02 Thread Nick Arnett
On Mon, Nov 2, 2009 at 3:30 AM, Julien Petitperrin <
julien.petitper...@gmail.com> wrote:

> Hello,
>
> I had this kind of issue a few days ago. I found this:
>
>
> http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/
>
> I hope this helps you to find a way to do your multiple items edit form.



Ah, that does look helpful and I wondered it I might do better to create one
form per line, as it suggests.

Nick

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



Legacy database - does every table need an id column?

2009-11-01 Thread Nick Arnett

I'm hoping to use Django with a legacy database and I'm suspecting
that things are not working as they should because the database has
tables that lack the "id" column that Django generates from the same
model.  Searching the documentation, I don't see anything that
indicates this is required, but I'm bumping into problems that I
believe are due to this.

The tables in question have a primary key that consists of two foreign
keys.

Anybody know?

I was hoping to use the data as-is... and I'm not sure if I can just
add an auto-increment "id" column to the tables who use the foreign
key combination as their primary keys.

As I ask the question, it now seems clear to me that the column is
needed.

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



Form that updates a list of items?

2009-10-31 Thread Nick Arnett

I'm just getting familiar with Django and I think I've got all the
basics... and I have lots of experience with Python and MySQL, but I'm
having a hard time figuring out how to do something that would be easy
for me in plain Python.  One of the problems I keep finding with
various pieces of documentation is that they show code snippets
without showing *where* they go... sometimes that's obvious, but
sometimes not so much.  Anyway, a little guidance on this simple thing
would help me immensely.

I need to create a form that updates values for a bunch of database
rows.  The wrinkle is that the model from which I'm getting the form
data isn't the same as the model I'm going to update.  The form should
look like a list of values followed by several checkboxes.  The user
will look down the list and check off the appropriate boxes.  When
submitted, the form should update corresponding Boolean fields in the
target table.

The reason there are two underlying tables and models is that the
source is a rollup of the target; they are essentially identical, but
querying the raw data is slow, so the system does a rollup
periodically, from which the form needs to grab an ordered list.

So... I need to populate the form with the name and ids of a number of
rows from the source table (pardon me for mixing database and object
terminology here...) and I can't figure how to do that.  Obviously
there's a for loop involved, but, well, I just can't quite grok how to
put this together.

Processing the form means updating the target with the new Boolean
values selected by the user in the form, of course.

If anybody has an example that does something like this, that'll be
great.

Thanks in advance,

Nick



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