null values should work here but don't

2009-06-23 Thread K.C. Smith

I want to (optionally) leave some fields in a model/table NULL.  I've
set the options "null=True" and "blank=True" for the fields in
question.  I know it's working because the admin site add form greyed
out the "blank=True" fields.  But, I still can't add an object with
these fields blank/NULL.  I get this error (in part):

Exception Type: DataError
Exception Value:invalid input syntax for type inet: ""
Exception Location: /usr/local/lib/python2.5/site-packages/django/db/
backends/util.py in execute, line 19
Python Executable:  /usr/local/bin/python
Python Version: 2.5.4

I'm using Postgres and the psycopg2-2.0.9 module. And other models/
tables without null values are working fine.

I did check the DB to make sure that "not null" wasn't set.  I even
dropped the table and then did another syncdb.  But, I still keep
getting this same error.

To try to test whether the error was coming from the DB or Django, I
inserted a couple of rows manually: once specifying the columns (and
omitting the nulls), and once by using the NULLs explicitly).
Succeeded both times, so I'm inclined to believe that this error is
coming from Django and not the database. Any ideas?  Thanks.

K.C.

--~--~-~--~~~---~--~~
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: null values should work here but don't

2009-06-24 Thread K.C. Smith

Thanks so much!

A bug: The good news is you're not crazy; the bad news is there's no
easy fix. :)

But, in fact, I applied one of the patches there and it solved the
problem very well.

K.C.

On Jun 23, 9:28 pm, Karen Tracey  wrote:
>
> Looks like:
>
> http://code.djangoproject.com/ticket/5622
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how do I model an auto-populate name from admin authorised users list

2012-02-10 Thread K.C. Smith
You have a lot of big questions and you'll need to do some more
learning of and practice Django to answer them all.  But, I will try
to answer some and point you in the right direction.

First, you linked a snippet of what seems to be your "models.py" file,
but much of what you wish to do will probably have to be accomplished
at the view layer in the "view.py" file.  At the view layer, you
handle requests and the user model for the current/requesting user is
accessible there.  (See here, for detailed information:
https://docs.djangoproject.com/en/1.2/topics/auth/#users .)  Code that
might allow you to get the user's name and email information might
look like this:

if request.user.is_authenticated() :
contextdict['email'] = request.user.email
contextdict['fn'] = request.user.first_name
contextdict['ln'] = request.user.last_name
if request.user.is_staff :
contextdict['sho_alnk'] = True
return render_to_response('template.html', contextdict )

Then you could access those var.s in the contextdict from your web
template and use them to pre-populate your form, or display them
statically perhaps.

The link above also has information about groups and permissions,
which should help with your second question.  Another technique that
might help in getting a list of usernames into a model (and hence a
drop-down selection on the admin page) would be to add a field like
this to the model:

approver = models.ForeignKey(User , limit_choices_to =
{'is_staff':True} )

That's not exactly what you've described, but there ought to be a way
to modify it to get "limit_choices_to" to use the group you create
rather than the boolean field User.is_staff .

Good luck.

K.C.

On Feb 3, 4:40 am, Krondaj  wrote:
> Hi,
>
> I have written a model for a web form (of sorts) I'm making that
> people can fill in from the admin site.  I have set permissions from
> the admin end so they can only write or change new posts of the form
> (seehttp://dpaste.org/BZ5Nm/). it's still work in progress  but I
> have two problems.
>
> First instead of using a CharField to take their name, i'd like it to
> auto populate, there full name and email address as they will be
> logged in and authenticated at the admin login site.
>
> Secondly instead of having a set of name choices for the approver i'd
> like to make a group in the admin called approver, and have it let you
> select from a list (so if we have a new approver i can just add them
> to the group).  I know how to make the group, i just don't know how to
> get the model to display these in the admin site as a drop-down list.
>
> I'd also like the database to link the first form and the second
> form... and make it so only the person who has been requested to do
> the work can fill in the required fields.
>
> Can anyone give me some clues/ell me how to do this My coding
> skillz are somewhat lacking!!??!! so i'd really appreciate any 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ConditionalGetMiddleware question

2011-11-11 Thread K.C. Smith
Hi,

I'm interested in enabling this middleware module.  The Django doc.s
don't say much about this module.  From looking at the code, however,
and reading about these mechanisms it appears that the module will do
nothing unless the 'ETag' and/or the 'Last-Modified' properties are
already set on the response object.  Is that correct?

Thanks in advance.

K.C.



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



Re: Why does Django create Postgres timestamp columns with time zones?

2011-11-12 Thread K.C. Smith
It's not required by PostgreSQL.  See,
http://www.postgresql.org/docs/8.4/interactive/datatype-datetime.html
, for example.

You may be able to change the data type of that column directly in the
database.  (See 
http://www.postgresql.org/docs/8.4/interactive/ddl-alter.html#AEN2595
.)

Maybe "ALTER TABLE notification_notice ALTER COLUMN created TYPE
timestamp without time zone ;"

K.C.

On Nov 11, 7:32 pm, Kevin  wrote:
> I thought that Django created datetime columns that were time zone
> agnostic, but when I looked at my Postgres table I saw that the values
> recorded there have time zone information.
>
> Going further I found that the Postgres backend directs Django to create
> columns that use time zones.
>
> From django/db/backends/postgresql/creation.py:
>
>     data_types = {
>             ...
>             'DateTimeField':     'timestamp with time zone',
>             ...
>
> The schema shows that the created column is specified as "timestamp with
> time zone".
>
>     CREATE TABLE notification_notice
>     (
>       ...
>       created timestamp with time zone NOT NULL,
>       ...
>
> The Postgres log shows the update statement that was sent. Django
> constructed a SQL statement that used UTC as the time zone as directed by
> my Django settings file.
>
>     UPDATE "notification_notice" SET "sender_id" = 1, "group_id" = NULL,
> "notice_type_id" = 1, "content_type_id" = 21, "object_id" = 3, "created" =
> E'2011-11-11 22:31:08.022148' WHERE "notification_notice"."id" = 14
>
> This is what my table looks like. The created column has a timestame that
> has "-08" for its time zone. Postgres must be inspecting the time zone of
> my system clock to find the time zone.
>
>     my_db=# select * from notification_notice limit 1;
>      id | sender_id | group_id | notice_type_id | content_type_id |
> object_id |           created            | last_interaction_time
>
> +---+--++-+---+ 
> --+---
>       1 |           |        3 |             21 |              53 |
> 6 | 2011-11-11 14:31:02.98882-08 |
>     (1 row)
>
> Questions:
> Doesn't Django have a hands off policy to time zones?
> Why does the Postgres backend use time zones for models.DateTimeField? Is
> this required by Postgres?
> Is there a way to force Django to create timestamp columns in Postgres that
> don't use the time zone?

-- 
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: ConditionalGetMiddleware question

2011-11-15 Thread K.C. Smith
To clarify, if I just enable the "ConditionalGetMiddleware" module it
won't change anything unless I also put in code to set the 'ETag' or
'Last-Modified' properties on responses for the pages that I want it
to work with?

That's my interpretation from reading a few sources on the subject.

Has anyone else enabled "ConditionalGetMiddleware" and measured the
results?

K.C.

On Nov 11, 4:01 pm, "K.C. Smith"  wrote:
> Hi,
>
> I'm interested in enabling this middleware module.  The Django doc.s
> don't say much about this module.  From looking at the code, however,
> and reading about these mechanisms it appears that the module will do
> nothing unless the 'ETag' and/or the 'Last-Modified' properties are
> already set on the response object.  Is that correct?
>
> Thanks in advance.
>
> K.C.

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



no plus-sign to add related object in admin

2011-12-29 Thread K.C. Smith
I've got a project where when I pull up the admin page to add an
object (an object that has several foreign keys), some of the FK
fields show the little green plus-sign links to add a new related
object for that field and other FK fields do not.

In the past, I've seen the plus-sign link to add a new related object
on all of the FK fields.  Why would it not show up?

I'm using Django 1.2.5.

K.C.

-- 
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: no plus-sign to add related object in admin

2011-12-30 Thread K.C. Smith
Thanks for your input.  I think you're probably right about non-
editable objects.  Unfortunately, that's not it in this case.

K.C.

On Dec 29, 4:07 pm, Furbee  wrote:
> Just taking a stab in the dark, are the ones without the + sign editable in
> the Admin? If they are not editable, I would imagine Django would not show
> the + in the Admin.
>
> Furbee
>
>
> On Thu, Dec 29, 2011 at 12:58 PM, K.C. Smith  wrote:
> > I've got a project where when I pull up the admin page to add an
> > object (an object that has several foreign keys), some of the FK
> > fields show the little green plus-sign links to add a new related
> > object for that field and other FK fields do not.
>
> > In the past, I've seen the plus-sign link to add a new related object
> > on all of the FK fields.  Why would it not show up?
>
> > I'm using Django 1.2.5.
>
> > K.C.
>

-- 
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: no plus-sign to add related object in admin

2011-12-30 Thread K.C. Smith
Hi, Oleg.  I've discovered the issue (for my case, anyway).  It goes
beyond the field definition.

The issue is that the FK fields which have no plus sign also have no
independent admin pages.  Instead, they are administered underneath
another object as inlines.  I have code in "admin.py" that is
analogous to this:


class kidsInline(admin.TabularInline) :
model = kids
extra = 5

class parentsAdmin(admin.ModelAdmin) :
inlines = [kidsInline]
save_on_top = True

admin.site.register(parents, parentsAdmin)


Then, it's the model "kids" that I have a FK field to in another
object, and it is that FK field that has no plus sign.  It makes sense
that it has no plus sign, as it has no registered, stand-alone page
for adding a new object of that type ("kids").

So, this really just changes my question.  I still want users to add
and edit the child object from the parent objects' admin page --
except in the case when they need to add a new one of those child
objects from the third object's add/edit page.   ...   A simple way to
accomplish this might be if I could register the "kids" object with
the admin site (with say "admin.site.register(kids) "), but have it
NOT appear on the main "Site administration" page.  I've been pouring
over the documentation and cannot see any way to do this.
"ModelAdmin" has so many options, though, that I'm still searching for
some sort of work-around.

K.C.

On Dec 30, 11:32 am, Oleg Korsak 
wrote:
> Hi. Could you paste full field definition in your case? I have same
> problem and looks like I know when it doesn't have plus sign
>
> >> On Thu, Dec 29, 2011 at 12:58 PM, K.C. Smith  wrote:
> >> > I've got a project where when I pull up the admin page to add an
> >> > object (an object that has several foreign keys), some of the FK
> >> > fields show the little green plus-sign links to add a new related
> >> > object for that field and other FK fields do not.
>
> >> > In the past, I've seen the plus-sign link to add a new related object
> >> > on all of the FK fields.  Why would it not show up?
>
> >> > I'm using Django 1.2.5.
>
> >> > K.C.
>

-- 
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: model for legacy table without primary key

2011-12-30 Thread K.C. Smith
You said the four fields are unique together, but "userid" sounds like
it should also be unique be itself, in which case it could be your PK.

In either case, you are being a bit an4l about something that matters
little.  You should probably just create another column for an auto-
incrementing PK.

K.C.

On Dec 30, 1:05 pm, akaariai  wrote:
> On Dec 30, 7:53 pm, Bill Beal  wrote:
>
> > But it can't be a primary key if the values are not unique, right?
> > The four fields are unique together, but not necessarily individually.
>
> It is not a real primary key. The idea is to tell Django it is a
> primary key even if it is not. And hope everything works OK (should
> work for most SELECT queries).
>
> So, it is just an ugly hack. Do not try this with writing queries,
> data corruption is guaranteed :)
>
> - Anssi

-- 
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: no plus-sign to add related object in admin

2012-01-05 Thread K.C. Smith
I have written a small patch that will add this feature (i.e., the
ability to register a model in the admin and stop it from showing up
in the index).  If your problem was the same as mine, then this can
get the plus signs where you want them without changing your preferred
admin view.  See https://code.djangoproject.com/ticket/17498 for
details.

K.C.

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