Re: Strange behavior with ModelForm and saving

2009-06-29 Thread Huuuze

StackOverflow to the rescue:

http://stackoverflow.com/questions/1059831/strange-behavior-with-modelform-and-saving

On Jun 29, 2:43 pm, Huuuze  wrote:
> This problem is very strange and I'm hoping someone can help me.  For
> the sake of argument, I have a Author model with ForeignKey
> relationship to the Book model.  When I display an author, I would
> like to have a ChoiceField that ONLY displays the books associated
> with that author.  As such, I override the AuthorForm.__init__()
> method and I create a List of choices (tuples) based upon a query that
> filters books based upon the author ID.  The tuple is a composite of
> the book ID and the book name (i.e., (1, 'Moby Dick')).  Those
> "choices" are then assigned to the ModelForm's choices attribute.
>
> When the form renders in the template, the ChoiceField is properly
> displayed, listing only those books associated with that author.
>
> This is where things get weird.
>
> When I save the form, I receive a ValueError (Cannot assign
> "u'1'":Author.book" must be a Book instance).  This error makes sense
> due to the FK relationship.  However, if I add a "print" statement to
> the code, make no other changes, and then save the record, it works.
> The ValueError magically disappears.  I've tried this a number of
> times, ensuring I haven't inadvertently made another change, and it
> works each time.
>
> Does anyone know what's going on here?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange behavior with ModelForm and saving

2009-06-29 Thread Huuuze

This problem is very strange and I'm hoping someone can help me.  For
the sake of argument, I have a Author model with ForeignKey
relationship to the Book model.  When I display an author, I would
like to have a ChoiceField that ONLY displays the books associated
with that author.  As such, I override the AuthorForm.__init__()
method and I create a List of choices (tuples) based upon a query that
filters books based upon the author ID.  The tuple is a composite of
the book ID and the book name (i.e., (1, 'Moby Dick')).  Those
"choices" are then assigned to the ModelForm's choices attribute.

When the form renders in the template, the ChoiceField is properly
displayed, listing only those books associated with that author.

This is where things get weird.

When I save the form, I receive a ValueError (Cannot assign
"u'1'":Author.book" must be a Book instance).  This error makes sense
due to the FK relationship.  However, if I add a "print" statement to
the code, make no other changes, and then save the record, it works.
The ValueError magically disappears.  I've tried this a number of
times, ensuring I haven't inadvertently made another change, and it
works each time.

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



Re: Django bug that should be addressed: Idle timeouts do not clear session information

2009-03-17 Thread Huuuze

Malcolm, I believe you and appreciate your advice, but you need to
ease up.  You're getting hung up on semantics.  In this instance, I'm
simply differentiating between a user clicking a link that says
"Logout" (a.k.a, a manual logout) versus Django detecting the lack of
a session cookie and redirecting the user to a login page (a.k.a., an
automated logout).  From the user's perspective, they have been
automatically logged out.

With that out of the way, let's wrap this up.  Please correct me if
I'm incorrect in this psuedo-code description of the manual login/
automated logout process:

1.  User access Django-based website.
2.  Django generates a session cookie with an expiration date based
upon SESSION_COOKIE_AGE.  (In this example, it's set to 3600)
3.  User logs in
4.  User traverses website for one hour (3600 seconds)
5.  Browser removes expired cookie
6.  User attempts to click new link in Django-based website
7.  Django detects the missing cookie
8.  Django redirects user to login page
9.  Django generates session cookie, inserts a new record into
django.sessions, and leaves old session information in django.sessions
table

The problem I'm trying to solve at this point is to slip in a call to
an audit method between Steps 6 and 8.  As soon as Django realizes the
user's session is gone, I'd like to audit the "idle logout" (again,
this is from the user's perspective).  By "audit", I mean store a
database record in my person.audit table with the user's user ID and a
message noting their session has expired.

And I agree with you: I don't think this can be done and you (and
others) have provided enough explanation to convince me that there is
no simple solution.  I just wanted to make sure we're all on the same
page with respect to the problem I'm trying to resolve.


On Mar 17, 9:35 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-03-18 at 01:28 +, Paulo Köch wrote:
> > > Calling logout(), as the original poster requested doesn't achieve
> > > anything (it does nothing). If it did do something, it would still be a
> > > bad idea to call it, because the user could have already logged in again
> > > and logging them out would be unfortunate.
>
> > Doesn't this generate a new session_id?
>
> More importantly it sets the user's status to be logged out. If they had
> logged in again since their previous session expired, you have now just
> logged them out again. In the web business we call that "not friendly".
>
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django bug that should be addressed: Idle timeouts do not clear session information

2009-03-17 Thread Huuuze

Yes, it does generate new session_id.  The user has essentially told
Django to expire the session, which in turn results in a new session
key.

I'm starting to agree with Malcolm.  Outside of an elaborate solution,
this one may not be possible.  As soon as the session expires, Django
updates the records in the django.sessions table.  As such, the only
unique identifier for the user, "session_key", is overwritten.

If there is some straightforward way to intercept the call to update
that table at the time of the automated logout, I'm all ears.

On Mar 17, 9:28 pm, Paulo Köch  wrote:
> > Calling logout(), as the original poster requested doesn't achieve
> > anything (it does nothing). If it did do something, it would still be a
> > bad idea to call it, because the user could have already logged in again
> > and logging them out would be unfortunate.
>
> Doesn't this generate a new session_id?
>
> Cheers,
> Paulo Köch
--~--~-~--~~~---~--~~
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 bug that should be addressed: Idle timeouts do not clear session information

2009-03-17 Thread Huuuze

Paulo, thank you for the link, but I don't see how that will help.  To
help articulate the problem, here is a post I included on
StackOverflow.com:

>> I would like to audit when a user has experienced an idle timeout in my 
>> Django application. In other words, if the user's session cookie's 
>> expiration date exceeds the SESSION_COOKIE_AGE found in settings.py, the 
>> user is redirected to the login page. When that occurs, an audit should also 
>> occur.

>> Currently, I have configured some middleware to capture these events. 
>> Unfortunately, Django generates a new cookie when the user is redirected to 
>> the login page, so I cannot determine if the user was taken to the login 
>> page via an idle timeout or some other event.

>> From what I can tell, I would need to work with the "django_session" table. 
>> However, the records in this table cannot be associated with that user 
>> because the sessionid value in the cookie is reset when the redirect occurs.

>> I'm guessing I'm not the first to encounter this dilemma. Does anyone have 
>> insight into how to resolve the problem?


On Mar 16, 6:38 pm, Jacob Kaplan-Moss 
wrote:
> On Mon, Mar 16, 2009 at 4:46 PM, Huuuze  wrote:
> > Does anyone else agree with my viewpoints on this matter?  If so,
> > please post your comments in the ticket.
>
> Actually, the right way to get your viewpoint heard is to take the
> matter to the django-developers mailing list, where topics related to
> Django's development are discussed. You'll have more luck posting
> suggestions and criticism there than here or on the ticket tracker.
>
> However, please keep in mind that we're currently running up to Django
> 1.1, so it's likely that anything that's not an outright bug might be
> left by the wayside while we close bugs for the final release. If you
> don't get an immediate response, be patient and wait until a bit after
> the release when we all have a bit more time.
>
> Jacob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django bug that should be addressed: Idle timeouts do not clear session information

2009-03-16 Thread Huuuze

Care to elaborate with some sample code?

On Mar 16, 9:12 pm, Paulo Köch  wrote:
> A background sleeper (as opposed to worker) that would fire a signal
> upon timer expiration seems like a nice mechanism.
>
> Cheers,
> Paulo Köch
>
> On Tue, Mar 17, 2009 at 01:04, Jeff FW  wrote:
>
> > When you say "audit"--what do you mean?  By that, I mean, what do you
> > plan to do with the data?  Do you need to know the second someone
> > times out, or can you check later?
>
> > If you need to know immediately, I think you may need to do something
> > terrible with JavaScript.  If not, or you can at least wait a little
> > while--run a cron job (every minute, if you'd like) that finds all of
> > the sessions that are past their expiration date.  You can log them as
> > you'd like, and then clear them out.
>
> > -Jeff
>
> > On Mar 16, 8:56 pm, Huuuze  wrote:
> >> Jeff (and Jacob)...
>
> >> I appreciate your responses and I stand corrected.  With that being
> >> said, are either of you (or anyone reading this) aware of a method
> >> that would allow me to track idle session timeouts?  I'd like to audit
> >> when a user has been logged out due to a timeout.
>
> >> Huuuze
>
> >> On Mar 16, 7:49 pm, Jeff FW  wrote:
>
> >> > It's not a bug.  When a cookie expires, the browser stops sending it
> >> > with its requests--therefore, there is *no* way for Django to know
> >> > that the cookie (and therefore, the session) has expired.  There is no
> >> > "timeout" happening on the server side, so the session can't get
> >> > cleared out.  Hence, why the documented method for clearing out old
> >> > sessions.
>
> >> > Maybe you're used to something like PHP's behavior, which cleans old
> >> > old sessions automatically.  However, it only does this by deciding to
> >> > clear out the old sessions (by default) 1 out of every 100 requests--
> >> > which is kind of a nasty thing to do that 100th person.
>
> >> > -Jeff
>
> >> > On Mar 16, 6:38 pm, Jacob Kaplan-Moss 
> >> > wrote:
>
> >> > > On Mon, Mar 16, 2009 at 4:46 PM, Huuuze  wrote:
> >> > > > Does anyone else agree with my viewpoints on this matter?  If so,
> >> > > > please post your comments in the ticket.
>
> >> > > Actually, the right way to get your viewpoint heard is to take the
> >> > > matter to the django-developers mailing list, where topics related to
> >> > > Django's development are discussed. You'll have more luck posting
> >> > > suggestions and criticism there than here or on the ticket tracker.
>
> >> > > However, please keep in mind that we're currently running up to Django
> >> > > 1.1, so it's likely that anything that's not an outright bug might be
> >> > > left by the wayside while we close bugs for the final release. If you
> >> > > don't get an immediate response, be patient and wait until a bit after
> >> > > the release when we all have a bit more time.
>
> >> > > Jacob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django bug that should be addressed: Idle timeouts do not clear session information

2009-03-16 Thread Huuuze

Jeff (and Jacob)...

I appreciate your responses and I stand corrected.  With that being
said, are either of you (or anyone reading this) aware of a method
that would allow me to track idle session timeouts?  I'd like to audit
when a user has been logged out due to a timeout.

Huuuze

On Mar 16, 7:49 pm, Jeff FW  wrote:
> It's not a bug.  When a cookie expires, the browser stops sending it
> with its requests--therefore, there is *no* way for Django to know
> that the cookie (and therefore, the session) has expired.  There is no
> "timeout" happening on the server side, so the session can't get
> cleared out.  Hence, why the documented method for clearing out old
> sessions.
>
> Maybe you're used to something like PHP's behavior, which cleans old
> old sessions automatically.  However, it only does this by deciding to
> clear out the old sessions (by default) 1 out of every 100 requests--
> which is kind of a nasty thing to do that 100th person.
>
> -Jeff
>
> On Mar 16, 6:38 pm, Jacob Kaplan-Moss 
> wrote:
>
> > On Mon, Mar 16, 2009 at 4:46 PM, Huuuze  wrote:
> > > Does anyone else agree with my viewpoints on this matter?  If so,
> > > please post your comments in the ticket.
>
> > Actually, the right way to get your viewpoint heard is to take the
> > matter to the django-developers mailing list, where topics related to
> > Django's development are discussed. You'll have more luck posting
> > suggestions and criticism there than here or on the ticket tracker.
>
> > However, please keep in mind that we're currently running up to Django
> > 1.1, so it's likely that anything that's not an outright bug might be
> > left by the wayside while we close bugs for the final release. If you
> > don't get an immediate response, be patient and wait until a bit after
> > the release when we all have a bit more time.
>
> > Jacob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django bug that should be addressed: Idle timeouts do not clear session information

2009-03-16 Thread Huuuze

I opened the following ticket which was unceremoniously closed by a
committer:

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

Here is the text from the ticket:
>> I have set the SESSION_COOKIE_AGE value in my settings.py file to expire 
>> sessions after 1 hour. Django successfully logs the user out of the session, 
>> however, the backend does not behave as one would expect in this situation. 
>> If a user logged out under normal conditions (i.e., clicks a "Logout" link), 
>> the session information is cleared from the "django.sessions" table. As 
>> such, I would expect an idle timeout (which is just a timed logout) to 
>> behave in the same manner. Unfortunately, Django simply creates a new 
>> session entry in the "django.sessions" table and the old, expired session 
>> remains in the table. The end result is a bloated "django.sessions" table 
>> that needs to be maintained through an external script.

The reason for closing the ticket was the following:

>> This is the documented behavior. See 
>> http://docs.djangoproject.com/en/dev/topics/http/sessions/#clearing-the-session-table

And my response:

>> I completely disagree with this assessment. Just because it's "documented 
>> behavior" doesn't make it correct.

>> Django terminates the session based upon the expiring cookie. As such, the 
>> timeout process should call "django.contrib.auth.logout", which clears out 
>> records from the django.sessions table.

>> How is the process of idling out any different from the user explicitly 
>> clicking a logout link? One is an implicit logout, whereas the other is an 
>> explicit logout. At the end of the day, its the same net result -- a user's 
>> session has ended. This behavior should be fixed.

Does anyone else agree with my viewpoints on this matter?  If so,
please post your comments in the ticket.  IMO, this is a bug in Django.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I determine when a user has an idle timeout in Django?

2009-03-16 Thread Huuuze

I would like to audit when a user has experienced an idle timeout in
my Django application. In other words, if the user's session cookie's
expiration date exceeds the SESSION_COOKIE_AGE found in settings.py,
the user is redirected to the login page. When that occurs, an audit
should also occur.

Currently, I have configured some middleware to capture these events.
Unfortunately, Django generates a new cookie when the user is
redirected to the login page, so I cannot determine if the user was
taken to the login page via an idle timeout or some other event.

>From what I can tell, I would need to work with the "django_session"
table. However, the records in this table cannot be associated with
that user because the sessionid value in the cookie is reset when the
redirect occurs.

I'm guessing I'm not the first to encounter this dilemma. Does anyone
have insight into how to resolve the problem?

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



SESSION_SAVE_EVERY_REQUEST behavior is overkill

2008-10-03 Thread Huuuze

I recently added "SESSION_SAVE_EVERY_REQUEST".  As the name implies,
the session ID is changed for every request made to the server.  IMO,
this is overkill.  If your page has 10 images on it, the session ID
will be changed 11 times (once for the initial page request and then
10 more times for each image file request).  This also means 11 writes
to the DB (django_session), which could be problematic for some
publicly hosted sites.

It'd be nice if the behavior of this setting only refreshed the
session on the initial page request and not EVERY request.

Does anyone else agree?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Why does Django generate HTTP 500 errors for static media when Debug is set to False?

2008-09-23 Thread Huuuze

There are no tracebacks in this instance.  I can see the non-descript
500 errors appearing in my terminal window.

On Sep 23, 12:06 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Tue, Sep 23, 2008 at 11:53 AM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > I'm preparing to deploy my Django app and I noticed that when I change
> > the "DEBUG" setting to False, all references to static files (i.e.,
> > JavaScript, CSS, etc..) result in HTTP 500 errors.
>
> > Any idea what's causing that issue (and how to fix it)?
>
> No. An idea for getting enough information to figure it out, though, is to
> configure things in settings.py (ADMINS, the various EMAIL_HOST,
> EMAIL_HOST_USER, etc. settings) so that you get the tracebacks for these
> errors mailed to you.
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Why does Django generate HTTP 500 errors for static media when Debug is set to False?

2008-09-23 Thread Huuuze

I'm preparing to deploy my Django app and I noticed that when I change
the "DEBUG" setting to False, all references to static files (i.e.,
JavaScript, CSS, etc..) result in HTTP 500 errors.

Any idea what's causing that issue (and how to fix 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Odd error when executing "runserver"

2008-09-17 Thread Huuuze

I got it working by using Psycopg 2 Beta 7, rather than Beta 8.  You
can DL it here:

http://www.initd.org/svn/psycopg/psycopg2/tags/2_0_BETA_7/

On Sep 17, 1:02 am, "Whyneedsgoogle2know?" <[EMAIL PROTECTED]>
wrote:
> Graham Dumpleton wrote:
> > On Aug 29, 6:43 am, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > > Is this an issue with Django, psycopg, or both?
>
> > The error 'Image not found' on MacOS X normally means that the .so
> > doesn't contain the object code for the architecture that the process
> > it is being loaded into requires.
>
> > This is normally an issue for mod_python and mod_wsgi on Leopard where
> > the operating system supplied Apache is compiled with 64 bit support
> > and so runs as 64 bit on latest hardware. What happens is that default
> > compilation options for Python packages only builds them as 32 bit and
> > thus the 64 bit architecture wouldn't be present in C extension
> > modules.
>
> > Since 'python' executable is not fully fat and only runs as 32 bit
> > even if have 64 bit CPU, that you are getting this error when using
> > "runserver" would indicate that you have installed pyscopg binaries
> > from PowerPC, or if you compiled it yourself, that you have set it up
> > to be 64 bit in mistaken belief that since you have 64 bit CPU that
> > you would want to.
>
> I encountered the same problem as described above. I compiled python
> manually and also compiled psycogp2. The are both i386 packages. But
> the problem still occurs:
>
> django.core.exceptions.ImproperlyConfigured: Error loading psycopg2
> module: dlopen(/usr/lib/python2.5/site-packages/psycopg2/_psycopg.so,
> 2): Library not loaded: libpq.5.dylib
>   Referenced from: /usr/lib/python2.5/site-packages/psycopg2/
> _psycopg.so
>   Reason: image not found
>
> Somebody suggested to look into it from the shell, but result is the
> same:
>
> Python 2.5.2 (r252:60911, Sep 17 2008, 06:47:26)
> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import psycopg2
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.5/site-packages/psycopg2/__init__.py", line
> 60, in 
>     from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
> ImportError: dlopen(/usr/lib/python2.5/site-packages/psycopg2/
> _psycopg.so, 2): Library not loaded: libpq.5.dylib
>   Referenced from: /usr/lib/python2.5/site-packages/psycopg2/
> _psycopg.so
>   Reason: image not found
>
> Any idea how to fix that?
>
> > Graham
>
> So long,
> Andrej
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Odd error when executing "runserver"

2008-08-28 Thread Huuuze

I recently installed PostgreSQL 8.3.3 and psycopg 2 (latest from
SVN).  When I attempt to start Django, I receive this error:

File "/Library/Python/2.5/site-packages/django/db/backends/
postgresql_psycopg2/base.py", line 20, in 
raise ImproperlyConfigured("Error loading psycopg2 module: %s" %
e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2
module: dlopen(/Library/Python/2.5/site-packages/psycopg2/_psycopg.so,
2): Library not loaded: /Users/buildfarm/pginstaller/server/staging/
osx/lib/libpq.5.dylib
  Referenced from: /Library/Python/2.5/site-packages/psycopg2/
_psycopg.so
  Reason: image not found

Is this an issue with Django, psycopg, or both?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django has "save_model", but what about "delete_model"?

2008-08-19 Thread Huuuze

The latest Django beta added this method to the admin models:

>> save_model(self, request, obj, form, change)

I have a business case where a "delete_model" method would come in
very handy.  Does anyone know if this will be included in an upcoming
release?

If not, here is my dilemma.  When an item is deleted from the admin
interface, I need to audit the activity using my custom audit
methods.  One of the attributes in the audit methods is the user ID of
the actor who executed the action.  In other words, when a delete
takes place, I'd like to audit who did it.  Unfortunately, I can't
seem to find a way to access the request object which will provide me
that information via the admin-related methods.

Any help is 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding save_add/save_change fails when using NFA?

2008-07-22 Thread Huuuze

I'd appreciate it if someone else chimed in, but it appears as though
the HOWTO contains a typo.  I've looked at the older versions of
Django and the NFA branch and none of them include the "model"
parameter in the "save_add" method.

Anyone else agree?

On Jul 22, 5:05 pm, Huuuze <[EMAIL PROTECTED]> wrote:
> I am using Django 1.0alpha and I'm attempting to modify the add/change
> behavior of my ModelAdmin.  As such, I'm following this example found
> on the Django wiki:
>
> http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowcanIchangewhere...
>
> Unfortunately, the method definition leads to the following error:
>
> >> TypeError at /admin/person/book/add/
> >> save_add() takes exactly 6 arguments (5 given)
>
> After reviewing the stack trace, the "options.py" file found in
> django.contrib.admin is only passing 4 explicit arguments (Line 487 in
> today's SVN trunk):
>
>     if all_valid(inline_formsets) and form.is_valid():
>         return self.save_add(request, form, inline_formsets, '../%s/')
>
> The example in the wiki includes a reference to a "model" parameter
> which isn't found on Line 487:
>
>     def save_add(self, request, model, form, formsets,
> post_url_continue):
>         pass
>
> If I remove that parameter from the method definition, a new error
> pops-up:
>
> >> AttributeError at /admin/person/book/add/
> >> 'NoneType' object has no attribute 'has_header'
>
> At this point, I've either encountered a bug or I'm not doing
> something right.  Any help you can provide is 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Overriding save_add/save_change fails when using NFA?

2008-07-22 Thread Huuuze

I am using Django 1.0alpha and I'm attempting to modify the add/change
behavior of my ModelAdmin.  As such, I'm following this example found
on the Django wiki:

http://code.djangoproject.com/wiki/NewformsHOWTO#Q:HowcanIchangewhereIgetsentaftersavinganewentrytothedatabase

Unfortunately, the method definition leads to the following error:

>> TypeError at /admin/person/book/add/
>> save_add() takes exactly 6 arguments (5 given)

After reviewing the stack trace, the "options.py" file found in
django.contrib.admin is only passing 4 explicit arguments (Line 487 in
today's SVN trunk):

if all_valid(inline_formsets) and form.is_valid():
return self.save_add(request, form, inline_formsets, '../%s/')

The example in the wiki includes a reference to a "model" parameter
which isn't found on Line 487:

def save_add(self, request, model, form, formsets,
post_url_continue):
pass

If I remove that parameter from the method definition, a new error
pops-up:

>> AttributeError at /admin/person/book/add/
>> 'NoneType' object has no attribute 'has_header'

At this point, I've either encountered a bug or I'm not doing
something right.  Any help you can provide is 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange error in admin interface when adding a new record (core.js and RelatedObjectLookups.js?)

2008-07-15 Thread Huuuze

Disregard.  Odd issue with my ADMIN_MEDIA_PREFIX.

On Jul 15, 2:13 pm, Huuuze <[EMAIL PROTECTED]> wrote:
> When I click the button to add a new Person object (one of my objects,
> not the User object) in the admin interface, I receive the following
> error in my console window:
>
> ERROR:  invalid input syntax for integer: "static_media/admin/js/
> core.js"
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person" WHERE
> "person_person"."id" = E'static_media/admin/js/core.js'
> ERROR:  invalid input syntax for integer: "static_media/admin/js/
> core.js"
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person" WHERE
> "person_person"."id" = E'static_media/admin/js/core.js'
> ERROR:  current transaction is aborted, commands ignored until end of
> transaction block
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person"
> [15/Jul/2008 17:57:54] "GET /admin/person/person/static_media/admin/js/
> core.js/ HTTP/1.1" 500 89312
> [15/Jul/2008 17:57:54] "GET /admin/person/person/static_media/admin/js/
> admin/RelatedObjectLookups.js HTTP/1.1" 301 0
> ERROR:  invalid input syntax for integer: "static_media/admin/js/admin/
> RelatedObjectLookups.js"
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person" WHERE
> "person_person"."id" = E'static_media/admin/js/admin/
> RelatedObjectLookups.js'
> ERROR:  invalid input syntax for integer: "static_media/admin/js/admin/
> RelatedObjectLookups.js"
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person" WHERE
> "person_person"."id" = E'static_media/admin/js/admin/
> RelatedObjectLookups.js'
> ERROR:  current transaction is aborted, commands ignored until end of
> transaction block
> STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
> "person_person"."last_name" FROM "person_person"
>
> The page still renders fine and the admin interface works, but it's
> odd that this error just started appearing.  Any thoughts?  For what
> it's worth, here is my Model and I'm using Postgresql:
>
> class Person(models.Model):
>     first_name = models.CharField(max_length=30, blank=True,
> null=True)
>     last_name = models.CharField(max_length=30, blank=True, null=True)
>
>     def __unicode__(self):
>         return ' '.join([self.first_name, self.last_name])
>
>     class Admin:
>         list_display = ('first_name', 'last_name')
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange error in admin interface when adding a new record (core.js and RelatedObjectLookups.js?)

2008-07-15 Thread Huuuze

When I click the button to add a new Person object (one of my objects,
not the User object) in the admin interface, I receive the following
error in my console window:

ERROR:  invalid input syntax for integer: "static_media/admin/js/
core.js"
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person" WHERE
"person_person"."id" = E'static_media/admin/js/core.js'
ERROR:  invalid input syntax for integer: "static_media/admin/js/
core.js"
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person" WHERE
"person_person"."id" = E'static_media/admin/js/core.js'
ERROR:  current transaction is aborted, commands ignored until end of
transaction block
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person"
[15/Jul/2008 17:57:54] "GET /admin/person/person/static_media/admin/js/
core.js/ HTTP/1.1" 500 89312
[15/Jul/2008 17:57:54] "GET /admin/person/person/static_media/admin/js/
admin/RelatedObjectLookups.js HTTP/1.1" 301 0
ERROR:  invalid input syntax for integer: "static_media/admin/js/admin/
RelatedObjectLookups.js"
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person" WHERE
"person_person"."id" = E'static_media/admin/js/admin/
RelatedObjectLookups.js'
ERROR:  invalid input syntax for integer: "static_media/admin/js/admin/
RelatedObjectLookups.js"
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person" WHERE
"person_person"."id" = E'static_media/admin/js/admin/
RelatedObjectLookups.js'
ERROR:  current transaction is aborted, commands ignored until end of
transaction block
STATEMENT:  SELECT "person_person"."id", "person_person"."first_name",
"person_person"."last_name" FROM "person_person"

The page still renders fine and the admin interface works, but it's
odd that this error just started appearing.  Any thoughts?  For what
it's worth, here is my Model and I'm using Postgresql:

class Person(models.Model):
first_name = models.CharField(max_length=30, blank=True,
null=True)
last_name = models.CharField(max_length=30, blank=True, null=True)

def __unicode__(self):
return ' '.join([self.first_name, self.last_name])

class Admin:
list_display = ('first_name', 'last_name')
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: customizing or extending ModelForm

2008-07-06 Thread Huuuze

You added an __init__ to your ModelForm class?  If so, try this: add a
"fields" definition to your ModelForm's Meta class that includes this
new field.  You can read more about it here:

http://www.djangoproject.com/documentation/modelforms/#using-a-subset-of-fields-on-the-form

On Jul 6, 5:35 am, chefsmart <[EMAIL PROTECTED]> wrote:
> > > >> self.fields['short_name'] = forms.CharField(label='Short Name', 
> > > >> max_length=9)
>
> > > This code would need to be added to an overridden __init__ in your
> > > ModelForm.
>
> I tried this, however it didnn't work. It seems like the form already
> exists when __init__ is executed.
>
> On Jul 3, 9:42 pm, chefsmart <[EMAIL PROTECTED]> wrote:
>
> > Thanks for the tip. I'm guessing this is for the newforms-admin or at
> > least the svn trunk. I'm not adding the extra field to the model
> > because it doesn't really belong there, though it's related to the
> > model.
>
> > On Jul 3, 6:10 pm, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > > Yes, you can do that, but you'd need to add it to the ModelForm's
> > > fields:
>
> > > >> self.fields['short_name'] = forms.CharField(label='Short Name', 
> > > >> max_length=9)
>
> > > This code would need to be added to an overridden __init__ in your
> > > ModelForm.  One question, however: why don't you add this field to
> > > your model?
>
> > > On Jul 3, 4:56 am,chefsmart<[EMAIL PROTECTED]> wrote:
>
> > > > Please see the following dpaste code.http://dpaste.com/60529/
>
> > > > There is a model, with a ModelForm. The ModelForm has a "short_name"
> > > > field that is not part of the model. Is this even possible/legal?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: customizing or extending ModelForm

2008-07-03 Thread Huuuze

Yes, you can do that, but you'd need to add it to the ModelForm's
fields:

>> self.fields['short_name'] = forms.CharField(label='Short Name', max_length=9)

This code would need to be added to an overridden __init__ in your
ModelForm.  One question, however: why don't you add this field to
your model?

On Jul 3, 4:56 am, chefsmart <[EMAIL PROTECTED]> wrote:
> Please see the following dpaste code.http://dpaste.com/60529/
>
> There is a model, with a ModelForm. The ModelForm has a "short_name"
> field that is not part of the model. Is this even possible/legal?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I get the value of a disabled Select widget?

2008-07-02 Thread Huuuze

I figured out the puzzle:

self.fields['state'] = forms.CharField(required=False,
widget=forms.HiddenInput(), initial=self.instance.state)

Still open to feedback since I'm new to Django.


On Jul 2, 11:19 am, Huuuze <[EMAIL PROTECTED]> wrote:
> I use the following code to disable a ModelForm field in a custom
> __init__:
>
> self.fields['state'] =
> USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'',
> 'tabindex':'-1',}, choices=STATE_CHOICES), required=False)
>
> Unfortunately, this presents a problem.  When I post the form with a
> "disabled" Select field, the form is no longer valid since it expects
> a value associated with State.  Under non-Django conditions, I'd add a
> hidden field that contains the value of the Select field and give it
> the same name as the Select field.  However, I'm having trouble
> figuring out how to retrieve the value of the Select field to place
> into a InputHidden field.  This is operating under the assumption that
> there isn't a better way to do this.  :)
>
> For the sake of argument, here is my ModelForm:
>
> class BookForm(forms.ModelForm):
>   class Meta:
>       model = Book
>
>     def __init__(self, *args, **kwargs):
>         super(BookForm, self).__init__(*args, **kwargs)
>         ... some other stuff happens here 
>         self.fields['state'] =
> USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'',
> 'tabindex':'-1',}, choices=STATE_CHOICES), required=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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I get the value of a disabled Select widget?

2008-07-02 Thread Huuuze

I use the following code to disable a ModelForm field in a custom
__init__:

self.fields['state'] =
USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'',
'tabindex':'-1',}, choices=STATE_CHOICES), required=False)

Unfortunately, this presents a problem.  When I post the form with a
"disabled" Select field, the form is no longer valid since it expects
a value associated with State.  Under non-Django conditions, I'd add a
hidden field that contains the value of the Select field and give it
the same name as the Select field.  However, I'm having trouble
figuring out how to retrieve the value of the Select field to place
into a InputHidden field.  This is operating under the assumption that
there isn't a better way to do this.  :)

For the sake of argument, here is my ModelForm:

class BookForm(forms.ModelForm):
  class Meta:
  model = Book

def __init__(self, *args, **kwargs):
super(BookForm, self).__init__(*args, **kwargs)
... some other stuff happens here 
self.fields['state'] =
USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'',
'tabindex':'-1',}, choices=STATE_CHOICES), required=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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to get form fields to show

2008-06-26 Thread Huuuze

> urlpatterns = patterns('',
>     (r'/step-1.html', 'billpay.views.DoPayDetailForm'),
> )
>
> Wouldn't this call the dopaydetailform view if you went to  the page /
> step-1.html ?

It's close.  Re-write it as such:

> urlpatterns = patterns('',
> (r'^step-1.html/$', billpay.views.DoPayDetailForm),
> )

The biggest change here is that I removed the single-quotes from
"billpay.views.DoPayDetailForm".
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Blank choice for USStateField?

2008-06-26 Thread Huuuze

You da man.  That worked perfectly.

Just out of curiosity, are the Django devs working on a patch?  I
wasn't able to find a ticket for this issue.


On Jun 26, 12:46 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
> On Jun 26, 8:29 am, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > How can I add an empty value as the initial value?
>
> At the moment you have do a bit of leg-work for this. Something like
> the following should work (untested)::
>
>     from django.contrib.localflavor.us.us_states import STATE_CHOICES
>     from django.contrib.localflavor.us.forms import USStateField
>
>     class YourModelForm(forms.ModelForm):
>         class Meta:
>             ...
>
>         YOUR_STATE_CHOICES = list(STATE_CHOICES)
>         YOUR_STATE_CHOICES.insert(0, ('', '-'))
>         state = USStateField(widget=forms.Select(
>                 choices=YOUR_STATE_CHOICES))
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Blank choice for USStateField?

2008-06-26 Thread Huuuze

I'm using a ModelForm to render a model that contains a
USStateField.

>> state = models.USStateField(blank=True, null=True)

Unfortunately, when it renders, the first selection is always
"Alabama" rather than "--" or some other defined blank value
(i.e., "Please select a state").  How can I add an empty value as the
initial value?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze

Found the answer why BookForm wasn't validating.  I needed to
"exclude" the author field from BookForm.  As soon as I did that,
everything fell into place.

Quick debugging tip for Django n00bs: I established that the missing
author was the problem by executing this line of code:

>> print BookForm(request.POST)

That displayed the HTML with the Django-supplied HTML errors.  I was
able to see that the form was expecting author and would not allow me
to proceed until I either a) supplied it with an author or b) excluded
it from the form.

Happy coding!

On Jun 25, 6:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> What you would do is:
>
> book_form = BookForm(request.POST)
> book = book_form.save(commit=False)
> book.author = author
> book.save()
>
> what save(commit=False) does, is create a model instance with the data
> from the form, but doesn't save it to the db, then you can handle it
> like a regular model.
>
> On Jun 25, 5:04 pm, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > For the sake of argument, I have two models:  Book and Author.  Book
> > has many fields and has a foreign key relationship with Author.
> > Author has two fields and no additional relationships.  To stay DRY, I
> > have BookForm and AuthorForm classes that I use to generate the HTML
> > for each class.
>
> > When I save, I do the following:
>
> > >> author = AuthorForm(request.POST).save()
>
> > This gives me the Author object for the author that was just inserted
> > into the DB.  Now I'd like to insert Book into the database, however,
> > I need to include Author due to the FK relationship.  As such...
>
> > >> book = BookForm(request.POST).save()
>
> > ...won't work.  How can I go about inserting the book record once I
> > have the author record?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze

Thanks for the tip.  I've now run into another issue.  My book isn't
validating.  Is there a quick way to figure out what field(s) are
causing this error:

The Book could not be created because the data didn't validate.


On Jun 25, 6:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> What you would do is:
>
> book_form = BookForm(request.POST)
> book = book_form.save(commit=False)
> book.author = author
> book.save()
>
> what save(commit=False) does, is create a model instance with the data
> from the form, but doesn't save it to the db, then you can handle it
> like a regular model.
>
> On Jun 25, 5:04 pm, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > For the sake of argument, I have two models:  Book and Author.  Book
> > has many fields and has a foreign key relationship with Author.
> > Author has two fields and no additional relationships.  To stay DRY, I
> > have BookForm and AuthorForm classes that I use to generate the HTML
> > for each class.
>
> > When I save, I do the following:
>
> > >> author = AuthorForm(request.POST).save()
>
> > This gives me the Author object for the author that was just inserted
> > into the DB.  Now I'd like to insert Book into the database, however,
> > I need to include Author due to the FK relationship.  As such...
>
> > >> book = BookForm(request.POST).save()
>
> > ...won't work.  How can I go about inserting the book record once I
> > have the author record?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I save records when using two forms joined by a foreign key?

2008-06-25 Thread Huuuze

For the sake of argument, I have two models:  Book and Author.  Book
has many fields and has a foreign key relationship with Author.
Author has two fields and no additional relationships.  To stay DRY, I
have BookForm and AuthorForm classes that I use to generate the HTML
for each class.

When I save, I do the following:

>> author = AuthorForm(request.POST).save()

This gives me the Author object for the author that was just inserted
into the DB.  Now I'd like to insert Book into the database, however,
I need to include Author due to the FK relationship.  As such...

>> book = BookForm(request.POST).save()

...won't work.  How can I go about inserting the book record once I
have the author record?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django inserts an empty string into IntegerField?

2008-06-25 Thread Huuuze

Between you and Karen, I've resolved the problem.  I had a bug here:

>> zip = forms.CharField(max_length=5, widget=widgets.TextInput({'size':5}), 
>> required=False)

That code has been changed to:

>> zip = forms.IntegerField(widget=widgets.TextInput({'size':5, 
>> 'maxlength':5}), required=False)

And good call on the USZipCodeField widget.  I'll be certain to make
us of that.

Side question:  I have noticed that empty CharFields (i.e., an empty
middle name value) get empty string values in the database rather than
null values.  This seems odd.  Is that by design with Django?  Here is
the code from my model for that ultimately gets rendered by my
ModelForm:

>> middle_name = models.CharField(max_length=30, blank=True, null=True)


On Jun 25, 5:02 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote:
> Huuuze wrote:
> > Thanks for getting back to me.  You're correct -- that article is not
> > a one-for-one match when compared to my problem, so let me tweak my
> > question.
>
> > When I attempt to save (my_form.save()) and I leave the zip code field
> > blank, I receive the following exception:
>
> > DataError at /person/new/add/
> > invalid input syntax for integer: ""
>
> > When I look at the insert statement, sure enough, an empty string is
> > attempting to make its way into my zip code field.
>
> > With that being said, do you expect that behavior?  If not, how can I
> > correct the issue?  If you do expect that behavior, how can I go about
> > creating a NullIntegerField?  This is new territory for me.
>
> I don't know what ver of Django you're using by my version certainly
> appears that it doesn't perform the way you say it does.  i.e. it looks
> like it does not allow "" for Integer fields.
>
> from '/django/db/models/fields/__init__.py'
>
> class IntegerField(Field):
>      empty_strings_allowed = False
>
> Although, It's possible my 3min analysis of what empty_strings_allowed
> does is wrong.  You'd have to look closer at the above file but it looks
> like overriding this
>
>      def get_db_prep_save(self, value):
>          "Returns field's value prepared for saving into a database."
>          return value
>
> is what your after.  I've not done this before though so "caveat
> programmer".
>
> btw, I really think IntegerField is the wrong column type for a zip
> code. They can be upto 11 chars long and have hyphens.  I'd make it
> CharField or maybe even a USZipCodeField from
> 'contrib/localflavor/us/forms.py' There's many others in localflavor if
> your flavor isn't US.
>
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> ___
> You've got fun!  Check out Austin360.com for all the entertainment
> info you need to live it up in the big city!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django inserts an empty string into IntegerField?

2008-06-25 Thread Huuuze

You're right -- I left out one detail.  To ensure the zip code field
renders in a more ideal manner, I added the following code to my
ModelForm:

>> zip = forms.CharField(max_length=5, widget=widgets.TextInput({'size':5}), 
>> required=False)

Adding "null=True" here doesn't seem to work.  Any thoughts?

On Jun 25, 4:44 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Jun 25, 2008 at 4:39 PM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > Thanks for getting back to me.  You're correct -- that article is not
> > a one-for-one match when compared to my problem, so let me tweak my
> > question.
>
> > When I attempt to save (my_form.save()) and I leave the zip code field
> > blank, I receive the following exception:
>
> > DataError at /person/new/add/
> > invalid input syntax for integer: ""
>
> > When I look at the insert statement, sure enough, an empty string is
> > attempting to make its way into my zip code field.
>
> > With that being said, do you expect that behavior?  If not, how can I
> > correct the issue?  If you do expect that behavior, how can I go about
> > creating a NullIntegerField?  This is new territory for me.
>
> No, I don't expect that behavior.  If I have an IntegerField with
> blank=True,null=True and create a ModelForm for the associated model, then
> when I fill in the form and leave that field blank, Django inserts a null
> into the database for that field, not a blank.  So something is going wrong
> in your case.  What level of Django are you using?  Snippets from your code
> might also help in identifying what is going wrong.
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django inserts an empty string into IntegerField?

2008-06-25 Thread Huuuze

Thanks for getting back to me.  You're correct -- that article is not
a one-for-one match when compared to my problem, so let me tweak my
question.

When I attempt to save (my_form.save()) and I leave the zip code field
blank, I receive the following exception:

DataError at /person/new/add/
invalid input syntax for integer: ""

When I look at the insert statement, sure enough, an empty string is
attempting to make its way into my zip code field.

With that being said, do you expect that behavior?  If not, how can I
correct the issue?  If you do expect that behavior, how can I go about
creating a NullIntegerField?  This is new territory for me.

On Jun 25, 4:28 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote:
> Huuuze wrote:
> > I have defined a zip code field as follows in my Address model:
>
> > zip = models.IntegerField(blank=True, null=True)
>
> > Being a good Djangonaut, I'm using a ModelForm to convert my address
> > model into HTML.  Now this where things get dicey.  As you can see in
> > the model, zip code can except empty values.  Unfortunately, when I
> > attempt to save data entered by a user who has left the zip code field
> > blank, I receive a database exception.  Apparently, Django is
> > attempting to insert an empty string into my integer-only field.
>
> > From what I can tell, this particular topic has been discussed
> > previously:
>
> >http://www.hoboes.com/Mimsy/?ART=595
>
> > Is the solution outlined in the blog post above the long-term solution
> > for Django developers or are there plans to have a ModelForm
> > understand that I would not want to insert an empty string into an
> > integer field?
>
> Are you sure it happens in IntegerFields, that's surprising.  That blog
> is talking about CharFields for which saving "" for None is less surprising.
>
> Instead of mucking with model's save method I'd create my own field,
> NullCharField or NullIntegerField that replaces "" or None with NULL
> according to the null=true parameter.
>
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> ___
> You've got fun!  Check out Austin360.com for all the entertainment
> info you need to live it up in the big city!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django inserts an empty string into IntegerField?

2008-06-25 Thread Huuuze

I have defined a zip code field as follows in my Address model:

zip = models.IntegerField(blank=True, null=True)

Being a good Djangonaut, I'm using a ModelForm to convert my address
model into HTML.  Now this where things get dicey.  As you can see in
the model, zip code can except empty values.  Unfortunately, when I
attempt to save data entered by a user who has left the zip code field
blank, I receive a database exception.  Apparently, Django is
attempting to insert an empty string into my integer-only field.

>From what I can tell, this particular topic has been discussed
previously:

http://www.hoboes.com/Mimsy/?ART=595

Is the solution outlined in the blog post above the long-term solution
for Django developers or are there plans to have a ModelForm
understand that I would not want to insert an empty string into an
integer field?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I add the user ID to a template?

2008-06-24 Thread Huuuze

I understand that.  However, I was hoping that the Django FRAMEWORK
would provide some easy mechanism for plucking that information out of
the session (rather than the request).  Many frameworks provide easy
methods for doing so and, guessing by your response, Django does not
provide not provide this functionality.

Having worked with my fair share of careless programmers, I'm simply
trying to do my due diligence on this topic and find an easy way to
resolve a minor issue.

On Jun 24, 11:01 am, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> The 'core' problem as you say, is essentially the core problem of all
> programming: programs don't write themselves.  You have to write appropriate
> code for what you are trying to do, what does it matter if someone forgets
> to add the username to the render call, or if someone forgets to add the 
> tags and the expected variable to the template?  At some point you have to
> expect developers to write appropriate code.  Even if there were a magic
> template tag that had direct access to the request object automatically,
> there is nothing stopping a developer from creating a new template and not
> using it.  Personally, I would'nt spend too much more time on this issue,
> either use RequestContext or pass the request.user to your template and
> leave it at that.  You could probably create a test that checked this and it
> may be prudent to put comments in the view or templates or a
> separate developers guide for your app to call out things like this. If you
> are really that concerned, you could always do something like this in your
> template:
>
> {% if username %}
> Hello {{username}}
> {% else %}
> Hello Nameless One. I wanted to address you by your proper name, but
> unfortunately some developer forgot to pass a variable to the template used
> to render me!  You should call and complain.
> {% endif %}
>
> :)
> -richard
>
> On 6/24/08, Huuuze <[EMAIL PROTECTED]> wrote:
>
>
>
> > Correct me if I'm wrong, but I'm not sure this resolves the core
> > problem.  In your example, I still need to add something (in this
> > case, 'context_instance=RequestContext(request)') to my
> > "render_to_response" statements.  I'd like to eliminate that
> > completely since it requires a developer to add something to the
> > render_to_response to get the username to render.  If the developer
> > forgets to add that, then the username doesn't display.
>
> > Long story short, is there a way to get the username to render using a
> > call that lives in the template and doesn't require repeated
> > references to a value in the view?  In other words, if I have five
> > pages and five distinct methods in the view that each have a
> > render_to_response, how can I avoid adding five
> > 'context_instance=RequestContext(request)' values to my
> > render_to_response statements?
>
> > I apologize in advance if using RequestContext does resolve this issue
> > -- still learning!
>
> > On Jun 24, 10:02 am, "Johan Liseborn" <[EMAIL PROTECTED]>
> > wrote:
> > > On Tue, Jun 24, 2008 at 15:47, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > > > A n00b question for everyone: My base template has a "Welcome
> > > > " section in it.  Currently, I'm adding the username (which
> > > > is coming from Django's auth/auth framework) to the template with the
> > > > following bit of code:
>
> > > > {{ request.session.user.username }}
>
> > > > This works, however, it requires me to add the "request" object to any
> > > > return statement that deals with displaying a page:
>
> > > > return render_to_response('somepage.html', {'request':request})
>
> > > > I'm guessing there's a better way to do this, but I can't seem to find
> > > > an answer.  Help!
>
> > > I believe you can use django.template.RequestContext to accomplish
> > > what you want; in your view, do something like:
>
> > > from django.template import RequestContext
>
> > > 
>
> > > return render_to_response('somepage.html',
> > > context_instance=RequestContext(request))
>
> > > That will, among other things (and depending on the
> > > TEMPLATE_CONTEXT_PROCESSORS variable in your settings.py) populate the
> > > request-object with a "user" field.
>
> > > You can read more here:
> >http://www.djangoproject.com/documentation/templates_python/#subclass...
>
> > > Cheers,
>
> > > johan
>
> > > --
> > > Johan Liseborn
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I add the user ID to a template?

2008-06-24 Thread Huuuze

Correct me if I'm wrong, but I'm not sure this resolves the core
problem.  In your example, I still need to add something (in this
case, 'context_instance=RequestContext(request)') to my
"render_to_response" statements.  I'd like to eliminate that
completely since it requires a developer to add something to the
render_to_response to get the username to render.  If the developer
forgets to add that, then the username doesn't display.

Long story short, is there a way to get the username to render using a
call that lives in the template and doesn't require repeated
references to a value in the view?  In other words, if I have five
pages and five distinct methods in the view that each have a
render_to_response, how can I avoid adding five
'context_instance=RequestContext(request)' values to my
render_to_response statements?

I apologize in advance if using RequestContext does resolve this issue
-- still learning!


On Jun 24, 10:02 am, "Johan Liseborn" <[EMAIL PROTECTED]>
wrote:
> On Tue, Jun 24, 2008 at 15:47, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > A n00b question for everyone: My base template has a "Welcome
> > " section in it.  Currently, I'm adding the username (which
> > is coming from Django's auth/auth framework) to the template with the
> > following bit of code:
>
> > {{ request.session.user.username }}
>
> > This works, however, it requires me to add the "request" object to any
> > return statement that deals with displaying a page:
>
> > return render_to_response('somepage.html', {'request':request})
>
> > I'm guessing there's a better way to do this, but I can't seem to find
> > an answer.  Help!
>
> I believe you can use django.template.RequestContext to accomplish
> what you want; in your view, do something like:
>
> from django.template import RequestContext
>
> 
>
> return render_to_response('somepage.html',
> context_instance=RequestContext(request))
>
> That will, among other things (and depending on the
> TEMPLATE_CONTEXT_PROCESSORS variable in your settings.py) populate the
> request-object with a "user" field.
>
> You can read more 
> here:http://www.djangoproject.com/documentation/templates_python/#subclass...
>
> Cheers,
>
> johan
>
> --
> Johan Liseborn
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I add the user ID to a template?

2008-06-24 Thread Huuuze

A n00b question for everyone: My base template has a "Welcome
" section in it.  Currently, I'm adding the username (which
is coming from Django's auth/auth framework) to the template with the
following bit of code:

{{ request.session.user.username }}

This works, however, it requires me to add the "request" object to any
return statement that deals with displaying a page:

return render_to_response('somepage.html', {'request':request})

I'm guessing there's a better way to do this, but I can't seem to find
an answer.  Help!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-20 Thread Huuuze

You da man.  This worked perfectly out of the box.  Thank you!

On Jun 19, 5:54 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
> On Jun 19, 3:45 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
>
> >                 if self.instance.state == 'processing':
> >                     queryset = queryset.exclude(state='new')
>
> The above lines aren't quite right ``self.instance`` is an instance of
> your ``SomeModel`` and presuming there is a foreign key to
> ``YourStateModel`` it should look something like this instead::
>
>                 ...
>                 if self.instance.state.name == 'processing':
>                     queryset = queryset.exclude(name='new')
>                 ...
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: eclipse + pydev + auto complete

2008-06-19 Thread Huuuze

You're off by one.  The value added to the PYTHONPATH (note, not
system path) should be:

/Library/Python/2.5/site-packages/

That will trigger the auto-complete for django classes.  One warning:
auto-completion for Model.objects is broken.  PyDev will flag that as
an error -- the author of PyDev is aware of the bug and I'm hoping
we'll see a fix in an upcoming release.


On Jun 19, 11:15 am, tom <[EMAIL PROTECTED]> wrote:
> hi,
>
> I wasn't able to find some information on this list about auto
> completion with eclipse. I managed to get auto completion for my
> projects, but not for django stuff. What I want to have for example
> is, when I enter models. that i get a list of available models, or
> forms. That's it. I have added /Library/Python/2.5/site-packages/
> django to the system path.
>
> Many thanks for your help!
>
> P.s: I use Mac OS X
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Huuuze

In this example, what if you wanted to selectively remove a value from
the choice list.  For example, let's say the list contained New, In
Process, and Closed.  When an item is "In Process", it cannot revert
back to "New".  As such, "New" should not be displayed amongst the
choices if "In Process" has been selected.

I realize I could eliminate the value using JavaScript on the front-
end, but is there a way to bake that logic into the form Model?

On Jun 7, 7:20 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
> On Jun 7, 4:18 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Quite a lot of work for something so simple
>
> I agree that overriding default widgets is currently too much work.
> But here's a slightly shorter version that works in exactly the same
> way as your example::
>
>     class SomeForm(forms.ModelForm):
>         class Meta:
>             model = SomeModel
>
>         car = forms.ModelChoiceField(Car.objects.all(),
>                 empty_label=None)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Select field not generating with form_for_instance?

2008-06-19 Thread Huuuze

Got it worked out using ModelForms.  Version 0.96.2 didn't include any
of these slick features.

For what its worth, I don't believe it would've ever worked using
v0.96.2.

On Jun 19, 11:01 am, Huuuze <[EMAIL PROTECTED]> wrote:
> On Jun 18, 7:32 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Wed, Jun 18, 2008 at 4:53 PM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > > I have the following model:
>
> > > class Publishers(models.Model):
> > >  books = models.CharField(maxlength=1, choices=BOOKS)
>
> > > BOOKS is a tuple:
> > > BOOKS = ( ('1', 'Book A'), ('2', 'Book B') )
>
> > > When I use form_for_instance(Publishers) to generate my template's
> > > HTML based upon the Publisher model, the books field is a standard
> > >  field rather than a  field.
>
> > You aren't actually passing the Publishers model to form_for_instance, are
> > you?  
>
> No.  I'm passing in an object.
>
> > That wouldn't work, you must be passing a Publishers model instance?
> > Or are you using form_for_model?
>
> I'm definitely using form_for_instance.
>
> > Is this a bug in Django or am I missing something?  If its th latter,
>
> > > how can I get the desired effect using my model (I realize I could
> > > create a custom form by coding a PublisherForm(forms.Form) -- trying
> > > to stay DRY).  From my perspective, it seems reasonable to expect the
> > > HTML to be a  field when a "choices" attribute is added to the
> > > model definition.
>
> > I just tried this with a similar model and a recent trunk checkout and
> > form_for_instance generated a select input for the field with choices, as
> > you would expect, so something is going awry with what you are doing.  I
> > can't really guess what, though, based on the information you provided.
>
> > What version of Django are you using?  
>
> I'm using Django 0.96.2.  Which version did you use in your tests?
>
> > Is there a reason you are using the
> > older form_for_ methods instead of the newer (and preferred) ModelForms?
>
> Can you elaborate on ModelForms?  I'm relying solely on Django taking
> my model and generating the HTML.  From what I can tell, using
> ModelForms would require me to repeat my code by creating a new class
> that defines the structure of the form.  Again, I'd prefer to stay DRY
> (don't repeat yourself), but if Django won't play nice, I'll be left
> with no choice.
>
>
>
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Select field not generating with form_for_instance?

2008-06-19 Thread Huuuze

One additional note: Can you post the code you used to get it working?

On Jun 18, 7:32 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Jun 18, 2008 at 4:53 PM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > I have the following model:
>
> > class Publishers(models.Model):
> >  books = models.CharField(maxlength=1, choices=BOOKS)
>
> > BOOKS is a tuple:
> > BOOKS = ( ('1', 'Book A'), ('2', 'Book B') )
>
> > When I use form_for_instance(Publishers) to generate my template's
> > HTML based upon the Publisher model, the books field is a standard
> >  field rather than a  field.
>
> You aren't actually passing the Publishers model to form_for_instance, are
> you?  That wouldn't work, you must be passing a Publishers model instance?
> Or are you using form_for_model?
>
> Is this a bug in Django or am I missing something?  If its th latter,
>
> > how can I get the desired effect using my model (I realize I could
> > create a custom form by coding a PublisherForm(forms.Form) -- trying
> > to stay DRY).  From my perspective, it seems reasonable to expect the
> > HTML to be a  field when a "choices" attribute is added to the
> > model definition.
>
> I just tried this with a similar model and a recent trunk checkout and
> form_for_instance generated a select input for the field with choices, as
> you would expect, so something is going awry with what you are doing.  I
> can't really guess what, though, based on the information you provided.
>
> What version of Django are you using?  Is there a reason you are using the
> older form_for_ methods instead of the newer (and preferred) ModelForms?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Select field not generating with form_for_instance?

2008-06-19 Thread Huuuze



On Jun 18, 7:32 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Jun 18, 2008 at 4:53 PM, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > I have the following model:
>
> > class Publishers(models.Model):
> >  books = models.CharField(maxlength=1, choices=BOOKS)
>
> > BOOKS is a tuple:
> > BOOKS = ( ('1', 'Book A'), ('2', 'Book B') )
>
> > When I use form_for_instance(Publishers) to generate my template's
> > HTML based upon the Publisher model, the books field is a standard
> >  field rather than a  field.
>
> You aren't actually passing the Publishers model to form_for_instance, are
> you?  

No.  I'm passing in an object.

> That wouldn't work, you must be passing a Publishers model instance?
> Or are you using form_for_model?
>

I'm definitely using form_for_instance.

> Is this a bug in Django or am I missing something?  If its th latter,
>
> > how can I get the desired effect using my model (I realize I could
> > create a custom form by coding a PublisherForm(forms.Form) -- trying
> > to stay DRY).  From my perspective, it seems reasonable to expect the
> > HTML to be a  field when a "choices" attribute is added to the
> > model definition.
>
> I just tried this with a similar model and a recent trunk checkout and
> form_for_instance generated a select input for the field with choices, as
> you would expect, so something is going awry with what you are doing.  I
> can't really guess what, though, based on the information you provided.
>
> What version of Django are you using?  

I'm using Django 0.96.2.  Which version did you use in your tests?

> Is there a reason you are using the
> older form_for_ methods instead of the newer (and preferred) ModelForms?

Can you elaborate on ModelForms?  I'm relying solely on Django taking
my model and generating the HTML.  From what I can tell, using
ModelForms would require me to repeat my code by creating a new class
that defines the structure of the form.  Again, I'd prefer to stay DRY
(don't repeat yourself), but if Django won't play nice, I'll be left
with no choice.

>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Select field not generating with form_for_instance?

2008-06-18 Thread Huuuze

I have the following model:

class Publishers(models.Model):
  books = models.CharField(maxlength=1, choices=BOOKS)

BOOKS is a tuple:
BOOKS = ( ('1', 'Book A'), ('2', 'Book B') )

When I use form_for_instance(Publishers) to generate my template's
HTML based upon the Publisher model, the books field is a standard
 field rather than a  field.

Is this a bug in Django or am I missing something?  If its the latter,
how can I get the desired effect using my model (I realize I could
create a custom form by coding a PublisherForm(forms.Form) -- trying
to stay DRY).  From my perspective, it seems reasonable to expect the
HTML to be a  field when a "choices" attribute is added to the
model definition.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HELP: Foreign keys, models, and querysets

2008-06-09 Thread Huuuze

Its a typo.  It should've been...

>> pid = models.ForeignKey(Person)

On Jun 9, 5:06 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> What is this `pid = models.ForiegnKey()` ?
>
> On 9 июн, 23:44, Huuuze <[EMAIL PROTECTED]> wrote:
>
> > I have the following models in my models.py file:
>
> > >> class Person(models.Model):
> > >>   pid = models.AutoField(primary_key=True)
> > >>   fname = models.CharField(max_length=50)
> > >>   lname = models.CharField(max_length=50)
> > >> class Books(models.Model)
> > >>   bid = models.AutoField(primary_key=True)
> > >>   name = models.CharField(max_length=50)
> > >>   pid = models.ForiegnKey()
>
> > In my views.py, I'd like to run a query that returns a list of people
> > and their books, where "st" are the "search terms" being passed into
> > the view:
>
> > >> results = Person.objects.filter(Q(fname__istartswith=st) | 
> > >> Q(lname__istartswith=st))
>
> > This only returns the "Person" object.  Is there a "Django-y" way to
> > have it return both associated objects?  From what I can tell, it
> > looks like I need to use "Person.objects.extra()" to tie in the
> > additional "where" statements.
>
> > I apologize in advance if I've missed something obvious.  New to
> > Django and just looking for help.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



HELP: Foreign keys, models, and querysets

2008-06-09 Thread Huuuze

I have the following models in my models.py file:

>> class Person(models.Model):
>>   pid = models.AutoField(primary_key=True)
>>   fname = models.CharField(max_length=50)
>>   lname = models.CharField(max_length=50)

>> class Books(models.Model)
>>   bid = models.AutoField(primary_key=True)
>>   name = models.CharField(max_length=50)
>>   pid = models.ForiegnKey()

In my views.py, I'd like to run a query that returns a list of people
and their books, where "st" are the "search terms" being passed into
the view:

>> results = Person.objects.filter(Q(fname__istartswith=st) | 
>> Q(lname__istartswith=st))

This only returns the "Person" object.  Is there a "Django-y" way to
have it return both associated objects?  From what I can tell, it
looks like I need to use "Person.objects.extra()" to tie in the
additional "where" statements.

I apologize in advance if I've missed something obvious.  New to
Django and just looking for help.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I build a database call using data in HttpRequest?

2008-06-06 Thread Huuuze

I have a method that evaluates the incoming "HttpRequest" from a
webpage.  As such, I'll use the following call to retrieve the data:

>> person_id = request.GET.get('person_id', '')

At this point, assuming I have a valid value for "some_id", I'd like
to use it in this statement:

>> results = Person.objects.get(person_id=???)
(NOTE: "person_id" is a member of the Person class)

I'm new to Python/Django, so my initial guess is that the "???" should
be replaced with either:

>> results = Person.objects.get(person_id='%d' % (person_id))

... or ...

>> results = Person.objects.get(person_id=person_id)

Is either guess correct?  I've been digging through DjangoBook.com and
I can't find any examples of this common paradigm.  HELP!
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



"Includes" directory?

2008-06-02 Thread Huuuze

I'm new to Django, so please be gentle.  Basic question: when
developing a web app, I've typically created an "includes" directory
which stores commonly used functions or methods.  From a best practice
standpoint, is it recommended that I create an "includes" directory
(not application) within my project?  If so, I'm guessing I can
reference it as "myproject.includes".

Please let me know if this approach is frowned upon in favor of some
other paradigm.  If so, can you show me an example of the preferred
method?

Thank you in advance.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---