Re: primary key auto increment with PostgreSQL and non Django standard column name

2011-05-28 Thread Malcolm Box
You need to tell django what the db column name for your pollkey field is. Look 
at the dbname field option in the docs. 


Sent from my iPhone, please excuse any typos

On 28 May 2011, at 05:13, Naoko Reeves  wrote:

> I see if column is set to AutoField then Django won't send INSERT poll_key
> as null.
> Now my problem is that it doesn't return newly assigned primary key value
> for me if primary key name is _key instead of _id
> It looks as if sequence name is not understood correctly.
> Could you tell me if
> 1) I need to change sequence name to something else? Currently it is
> poll_key_seq
> 2) Is there a way to specify the sequence name?
> 
> 
> class Poll(models.Model):
>poll_key = models.AutoField(primary_key=True)
>poll_question = models.CharField(max_length=200, default='')
> 
> class Poll2(models.Model):
>poll2_id = models.AutoField(primary_key=True)
>poll2_question = models.CharField(max_length=200, default='')
> 
 from mysite.polls.models import Poll2
 p3 = Poll2(poll2_question='3')
 p3.save()
 p3.pk
> 2L
 p4 = Poll2(poll2_question='4')
 p4.save()
 p4.pk
> 3L
 from mysite.polls.models import Poll
 p5 = Poll(poll_question='5')
 p5.save()
 print p5.pk
> None
> 
> 
> On 5/27/11 5:31 PM, "Casey Greene"  wrote:
> 
>> Doesn't autofield with primary_key=True handle this for you (instead of
>> making it an IntegerField):
>> 
>> https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield
>> 
>> Hope this helps!
>> Casey
>> 
>> On 05/27/2011 07:22 PM, Naoko Reeves wrote:
>>> Hi, I have a Django newbie question.
>>> My goal is to auto increment primary key with non Django standard column
>>> name.
>>> We are converting from existing database and primary key schema is
>>> "tablename_key" and not "id".
>>> I googled it and end up reaching to this ticket:
>>> https://code.djangoproject.com/ticket/13295
>>> So I understand that there is work in progress but I wanted find work
>>> around..
>>> 
>>> 1. My first try was to let postgres handle it.
>>> 
>>> my postgreSQL table looks like this:
>>> 
>>> CREATE TABLE poll
>>> (
>>>   poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
>>>   poll_question character varying(200) NOT NULL,
>>>   poll_pub_date timestamp with time zone NOT NULL,
>>>   CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
>>> )
>>> 
>>> My model look like this:
>>> class Poll(models.Model):
>>> poll_key = models.IntegerField(primary_key=True)
>>> poll_question = models.CharField(max_length=200, default='')
>>> poll_pub_date = models.DateTimeField('date published',
>>> default=datetime.date.today())
>>> class Meta:
>>> db_table = u'poll'
>>> 
>>> I was hoping that with this, I could
>>> p = Poll(poll_question="Question 1?")
>>> p.save()
>>> 
>>> but this fails because Django is actually sending the following statement:
>>> INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
>>> VALUES (NULL, 'Question 1?', NULL)
>>> 
>>> 
>>> 2. My Second attempt is then to add default to model
>>> 
>>> Created a function to return sequence value
>>> from django.db import connection
>>> def c_get_next_key(seq_name):
>>> """ return next value of sequence """
>>> c = connection.cursor()
>>> c.execute("SELECT nextval('%s')" % seq_name)
>>> row = c.fetchone()
>>> return int(row[0])
>>> 
>>> Calling like below works just fine. Everytime I call it, I get new number.
>>> c_get_next_key('poll_key_seq')
>>> 
>>> Then I modify Poll_key in Poll model as follows:
>>> Poll_key = models.IntegerField(primary_key=True,
>>> default=c_get_next_key('poll_key_seq'))
>>> 
>>> I went to Django Shell and created first record.
>>> p1 = Poll(poll_question="P1")
>>> p1.poll_key
>>> # this will return let's say 37
>>> p1.save()
>>> # saves just fine.
>>> 
>>> # instantiating new object
>>> p2 = Poll(poll_question="P2")
>>> p2.poll_key
>>> # this also return 37.
>>> 
>>> I know I must be doing something wrong... but could you pint me to right
>>> direction? I am expecting p2.poll_key to return 38.
>>> Thank you very much for your help in advance.
>>> 
>>> Naoko
>>> 
>>> 
>>> 
>>> 
>>> 
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Djan

Re: Installing Django on Ubuntu

2011-05-28 Thread Martin Tiršel

Hello,

only short reply:

1.) Don't use distro packages for python packages
2.) Instal some libraries you will need (libmysqlclient-dev, python-dev,  
build-essential, python-setuptools, ...)
3.) Install virtualenv (either using distro package or easy_install/pip if  
you want/need newer one), create new empty virtual environment (I am using  
~/.virtualenv for all environments):


virtualenv --no-site-packages ~/.virtualenv/django-1.2

4.) switch into that environment:

source ~/.virtualenv/django-1.2/bin/activate

5.) install python packages using pip or easy_install you will need:

pip install "django=1.2.5"
pip install mysql-python
pip install south
...

6.) start your project:

django-admin.py startproject someproject

and so on.

Remember, everytimes you want to work with that environment, you need to  
switch into it (uning source path/bin/activate). Many people beginnning  
with virtualenv forget this :)


Regards,
Martin



On Sat, 28 May 2011 04:27:42 +0200, DogGoesOut  
 wrote:



Hey, can anyone help me out? For some reason, django is not as easy as
it would appear to install on my ubuntu laptop. Here are the stats:
I'm running Ubuntu 10.10 Maverick Meerkat, and have Python 2.6
installed already,

So far, I've installed a subversion successfully, and am attempting to
create a symbolic link from django to python:

ln: creating symbolic link `/usr/local/bin/django-admin.py': File
exists
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ cd ~/sites/dev
bash: cd: /home/kyle/sites/dev: No such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /path/to/django-trunk/
django/bin/django-admin.py startproject djangoblog
python: can't open file '/path/to/django-trunk/django/bin/django-
admin.py': [Errno 2] No such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /usr/local/bin/django-
admin.py startproject djangoblog
python: can't open file '/usr/local/bin/django-admin.py': [Errno 2] No
such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$

Ignoring the middle (which included a typo or two) there's a statement
at the end of this code that makes no sense to me. The third line up
from the bottom, calls the file from the first line

 /usr/local/bin/django-admin.py

In the first line, this file is stated to exist. In the error message,
the computer states that it can't open the same file, and that no such
file or directory exists. This seems self-contradictory, and I'm not
sure where to go from here, as my python interpreter cannot understand
django yet. Any advice would be very much appreciated!

Thanks!


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



Odp: Re: Django Model Designer - UML

2011-05-28 Thread Mateusz Harasymczuk
This is a very good hint.
Somehow I had to skipped the inspectdb command.

There is humongous number of the DB designing tools.

Thank you.

-- 
You received this message because you are subscribed to the Google 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.



signals pre_save vs model's save()

2011-05-28 Thread Mateusz Harasymczuk
I am thinking about splitting my model's save() method over few signals.

For example, stripping spaces and making string capitalized.

I have even more sophisticated problems such as making an object field 
active set to False basing on various parameters from other fields, such as 
expiration date, or good or bad karma points.

What do you think, it is generally good idea, to keep models file clean out 
of heavily overloaded save() methods?

How about making more than one signal pre_save to the same model?


@receiver(pre_save, sender=X)
def strip_chars(sender, **kwargs):
pass

@receiver(pre_save, sender=X)
def capitalize_name(sender, **kwargs):
pass

@receiver(pre_save, sender=X)
def make_inactive(sender, **kwargs):
pass

Will it work?

I want to put those in signals/X.py
where X is my model name

Where to import them? in my model file?
or it will happen "automagicly" like with admin.py file?
(I think that python's explicit rule forbids that way, therefore where to 
import those signals, avoiding recurring imports [signal.py import model.py 
and model imports signals])?

-- 
You received this message because you are subscribed to the Google 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: Installing Django on Ubuntu

2011-05-28 Thread Nikhil Somaru
Hi,

To add to what Martin said, I use a bash alias  to
activate my environments, which makes it easier than navigating to that
directory every time I wanted to activate a specific environment.

There's a great guide for this here:
http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/

It's slightly old but it covers most of what is required.

On Sat, May 28, 2011 at 1:14 PM, Martin Tiršel  wrote:

> Hello,
>
> only short reply:
>
> 1.) Don't use distro packages for python packages
> 2.) Instal some libraries you will need (libmysqlclient-dev, python-dev,
> build-essential, python-setuptools, ...)
> 3.) Install virtualenv (either using distro package or easy_install/pip if
> you want/need newer one), create new empty virtual environment (I am using
> ~/.virtualenv for all environments):
>
> virtualenv --no-site-packages ~/.virtualenv/django-1.2
>
> 4.) switch into that environment:
>
> source ~/.virtualenv/django-1.2/bin/activate
>
> 5.) install python packages using pip or easy_install you will need:
>
> pip install "django=1.2.5"
> pip install mysql-python
> pip install south
> ...
>
> 6.) start your project:
>
> django-admin.py startproject someproject
>
> and so on.
>
> Remember, everytimes you want to work with that environment, you need to
> switch into it (uning source path/bin/activate). Many people beginnning with
> virtualenv forget this :)
>
> Regards,
> Martin
>
>
>
>
> On Sat, 28 May 2011 04:27:42 +0200, DogGoesOut <
> elizabethfalkne...@gmail.com> wrote:
>
>  Hey, can anyone help me out? For some reason, django is not as easy as
>> it would appear to install on my ubuntu laptop. Here are the stats:
>> I'm running Ubuntu 10.10 Maverick Meerkat, and have Python 2.6
>> installed already,
>>
>> So far, I've installed a subversion successfully, and am attempting to
>> create a symbolic link from django to python:
>>
>> ln: creating symbolic link `/usr/local/bin/django-admin.py': File
>> exists
>> kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ cd ~/sites/dev
>> bash: cd: /home/kyle/sites/dev: No such file or directory
>> kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /path/to/django-trunk/
>> django/bin/django-admin.py startproject djangoblog
>> python: can't open file '/path/to/django-trunk/django/bin/django-
>> admin.py': [Errno 2] No such file or directory
>> kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /usr/local/bin/django-
>> admin.py startproject djangoblog
>> python: can't open file '/usr/local/bin/django-admin.py': [Errno 2] No
>> such file or directory
>> kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$
>>
>> Ignoring the middle (which included a typo or two) there's a statement
>> at the end of this code that makes no sense to me. The third line up
>> from the bottom, calls the file from the first line
>>
>>  /usr/local/bin/django-admin.py
>>
>> In the first line, this file is stated to exist. In the error message,
>> the computer states that it can't open the same file, and that no such
>> file or directory exists. This seems self-contradictory, and I'm not
>> sure where to go from here, as my python interpreter cannot understand
>> django yet. Any advice would be very much appreciated!
>>
>> Thanks!
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Yours,
Nikhil Somaru

-- 
You received this message because you are subscribed to the Google 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: signals pre_save vs model's save()

2011-05-28 Thread Marcos Moyano
You can set more than 1 [pre,post]_save signal per-model, no problem. I
generally, and I'm not saying this is the django way, do it like this:
app_name/
 __init__.py
 modes.py
 views.py
 signals.py

Inside my signals.py I have all my signal declarations and connections.
And inside __init__.py I just do:

import app_name.signals

Rgds,
Marcos


On Sat, May 28, 2011 at 7:05 AM, Mateusz Harasymczuk  wrote:

> I am thinking about splitting my model's save() method over few signals.
>
> For example, stripping spaces and making string capitalized.
>
> I have even more sophisticated problems such as making an object field
> active set to False basing on various parameters from other fields, such as
> expiration date, or good or bad karma points.
>
> What do you think, it is generally good idea, to keep models file clean out
> of heavily overloaded save() methods?
>
> How about making more than one signal pre_save to the same model?
>
>
> @receiver(pre_save, sender=X)
> def strip_chars(sender, **kwargs):
> pass
>
> @receiver(pre_save, sender=X)
> def capitalize_name(sender, **kwargs):
> pass
>
> @receiver(pre_save, sender=X)
> def make_inactive(sender, **kwargs):
> pass
>
> Will it work?
>
> I want to put those in signals/X.py
> where X is my model name
>
> Where to import them? in my model file?
> or it will happen "automagicly" like with admin.py file?
> (I think that python's explicit rule forbids that way, therefore where to
> import those signals, avoiding recurring imports [signal.py import model.py
> and model imports signals])?
>
> --
> You received this message because you are subscribed to the Google 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.
>



-- 
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
You received this message because you are subscribed to the Google 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.



Odp: Re: signals pre_save vs model's save()

2011-05-28 Thread Mateusz Harasymczuk
So it should works.
Great.

my save() methods are much longer than models declaration, and I find it 
quite a bit confusing to maintain.
and for sure, to tell how it works :}

from PEP 20 -- The Zen of Python:

"

Simple is better than complex.

...

If the implementation is hard to explain, it's a bad idea.

"

-- 
You received this message because you are subscribed to the Google 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: markup

2011-05-28 Thread Vladimir
Has anyone any experience in CKeditor or tinymce using with django ?

On 26 май, 20:25, Oscar Carballal  wrote:
> 2011/5/26 Brett Parker :
>
> > On 26 May 08:27, Vladimir wrote:
> >> Is there a tool to transform MS WORD file into HTML ? I know there is
> >> markdown and textile, but I would prefer MS WORD.
>
> >http://wvware.sourceforge.net/
>
> > --
> > Brett Parker
>
> Alsohttp://ginstrom.com/software/doc2html/

-- 
You received this message because you are subscribed to the Google 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.



Regarding Django Applicaiton

2011-05-28 Thread Amit Pal
Hello,

I am Amit Pal , a undergrduate studentI need your help . I am new
at Django and just run the first application on my workstation.

I have to make a django applicaiton i.e.

TO build a website which shows the IP location (geoip) on Google
map I need your help very urgently ..

Waiting for your all response :)

-- 
You received this message because you are subscribed to the Google 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 register and login form

2011-05-28 Thread electrocoder
how do make django register and login form

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



Re: Preselected Radio button

2011-05-28 Thread Ndungi Kyalo
thanks bruno. and thanks for the advice on tuples too.
On 25 May 2011 17:30, "bruno desthuilliers" 
wrote:
> On May 25, 4:12 pm, Ndungi Kyalo  wrote:
>> Am trying to pre-select a radio button created with the django.forms
library :
>>
>> choices = forms.ChoiceField(
>> widget = forms.RadioSelect(),
>> choices = [
>> ['a', 'i liked it'],
>> ['b', 'i did not like it']
>> ],
>> required=True
>> )
>>
>> How would I go about getting the 'a' choice pre-selected on an unbound
form ?
>
> http://docs.djangoproject.com/en/1.3/ref/forms/api/#dynamic-initial-values
>
> IIRC, this should be enough.
>
> As a side note, you'd better use tuples than lists for your choices -
> at least for the "value, label" pairs which are semantically tuples,
> and possibly for the choices list itself but then it's more of a micro-
> optimisation (tuples are lest costly than lists).
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

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



Re: Regarding Django Applicaiton

2011-05-28 Thread Anoop Thomas Mathew
Hi Amit,
Welcome to django.
1.By th way, this is not the proper way to behave in a mailing list. First
learn that.
2. Run a basic app and try the tutorial at docs.djangoproject.com, only then
your'll understand what to ask.
3. Be more specific while asking questions, maximum descriptive as possible.

Helped!!!
;)
Best of luck man. You'll surely be helped if you ask specifically.

Regards,
Anoop
On 28 May 2011 18:14, "Amit Pal"  wrote:
> Hello,
>
> I am Amit Pal , a undergrduate studentI need your help . I am new
> at Django and just run the first application on my workstation.
>
> I have to make a django applicaiton i.e.
>
> TO build a website which shows the IP location (geoip) on Google
> map I need your help very urgently ..
>
> Waiting for your all response :)
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

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



Re: Regarding Django Applicaiton

2011-05-28 Thread Amit Pal
Thanks for quick reply..

It's very important to me

-- 
You received this message because you are subscribed to the Google 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.



ExtJS 4.0, Django and ExtDirect

2011-05-28 Thread Юлиян Попов


Do you know if I can use this Django Ext.Direct 
router with 
ExtJS 4.0? Do you have any examples where I can find how to do it? I'm new 
to JavaScript programming.

Will it be easy to integrate server side form validation with ExtJS? What 
about file upload?

Can I use ExtJS library drawing (or charts) to draw a hall where clients can 
click on empty seats and purchase a tickets? Do you know any other ajax 
library that can help me do this easier?
Also here: 
http://stackoverflow.com/questions/6162302/extjs-4-0-django-and-extdirect 

-- 
You received this message because you are subscribed to the Google 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: primary key auto increment with PostgreSQL and non Django standard column name

2011-05-28 Thread Naoko Reeves
Malcolm, Thank you for your advice!
I changed my model as follows:
poll_key = models.AutoField(primary_key=True, db_column='poll_key')
However, the result remain the same as shown below. If you could point me
out to right direction again, I would appreciate. Thank you very much for
your time.

>>> from mysite.polls.models import Poll2
>>> p3 = Poll2(poll2_question='3')
>>> p3.save()
>>> p3.pk
4L
>>> from mysite.polls.models import Poll
>>> p5 = Poll(poll_question='5')
>>> p5.save()
>>> print p5.pk
None


On 5/28/11 12:23 AM, "Malcolm Box"  wrote:

> You need to tell django what the db column name for your pollkey field is.
> Look at the dbname field option in the docs.
> 
> 
> Sent from my iPhone, please excuse any typos
> 
> On 28 May 2011, at 05:13, Naoko Reeves  wrote:
> 
>> I see if column is set to AutoField then Django won't send INSERT poll_key
>> as null.
>> Now my problem is that it doesn't return newly assigned primary key value
>> for me if primary key name is _key instead of _id
>> It looks as if sequence name is not understood correctly.
>> Could you tell me if
>> 1) I need to change sequence name to something else? Currently it is
>> poll_key_seq
>> 2) Is there a way to specify the sequence name?
>> 
>> 
>> class Poll(models.Model):
>>poll_key = models.AutoField(primary_key=True)
>>poll_question = models.CharField(max_length=200, default='')
>> 
>> class Poll2(models.Model):
>>poll2_id = models.AutoField(primary_key=True)
>>poll2_question = models.CharField(max_length=200, default='')
>> 
> from mysite.polls.models import Poll2
> p3 = Poll2(poll2_question='3')
> p3.save()
> p3.pk
>> 2L
> p4 = Poll2(poll2_question='4')
> p4.save()
> p4.pk
>> 3L
> from mysite.polls.models import Poll
> p5 = Poll(poll_question='5')
> p5.save()
> print p5.pk
>> None
>> 
>> 
>> On 5/27/11 5:31 PM, "Casey Greene"  wrote:
>> 
>>> Doesn't autofield with primary_key=True handle this for you (instead of
>>> making it an IntegerField):
>>> 
>>> https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield
>>> 
>>> Hope this helps!
>>> Casey
>>> 
>>> On 05/27/2011 07:22 PM, Naoko Reeves wrote:
 Hi, I have a Django newbie question.
 My goal is to auto increment primary key with non Django standard column
 name.
 We are converting from existing database and primary key schema is
 "tablename_key" and not "id".
 I googled it and end up reaching to this ticket:
 https://code.djangoproject.com/ticket/13295
 So I understand that there is work in progress but I wanted find work
 around..
 
 1. My first try was to let postgres handle it.
 
 my postgreSQL table looks like this:
 
 CREATE TABLE poll
 (
   poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
   poll_question character varying(200) NOT NULL,
   poll_pub_date timestamp with time zone NOT NULL,
   CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
 )
 
 My model look like this:
 class Poll(models.Model):
 poll_key = models.IntegerField(primary_key=True)
 poll_question = models.CharField(max_length=200, default='')
 poll_pub_date = models.DateTimeField('date published',
 default=datetime.date.today())
 class Meta:
 db_table = u'poll'
 
 I was hoping that with this, I could
 p = Poll(poll_question="Question 1?")
 p.save()
 
 but this fails because Django is actually sending the following statement:
 INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
 VALUES (NULL, 'Question 1?', NULL)
 
 
 2. My Second attempt is then to add default to model
 
 Created a function to return sequence value
 from django.db import connection
 def c_get_next_key(seq_name):
 """ return next value of sequence """
 c = connection.cursor()
 c.execute("SELECT nextval('%s')" % seq_name)
 row = c.fetchone()
 return int(row[0])
 
 Calling like below works just fine. Everytime I call it, I get new number.
 c_get_next_key('poll_key_seq')
 
 Then I modify Poll_key in Poll model as follows:
 Poll_key = models.IntegerField(primary_key=True,
 default=c_get_next_key('poll_key_seq'))
 
 I went to Django Shell and created first record.
 p1 = Poll(poll_question="P1")
 p1.poll_key
 # this will return let's say 37
 p1.save()
 # saves just fine.
 
 # instantiating new object
 p2 = Poll(poll_question="P2")
 p2.poll_key
 # this also return 37.
 
 I know I must be doing something wrong... but could you pint me to right
 direction? I am expecting p2.poll_key to return 38.
 Thank you very much for your help in advance.
 
 Naoko
 
 
 
 
 
 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To post to this gro

Re: django register and login form

2011-05-28 Thread Amanjeev Sethi
Django has a nice user authentication system. Have you started reading the
docs? I can point you to the auth page:
https://docs.djangoproject.com/en/1.3/topics/auth/

This page gives you the basics of authentication system in Django.

I have found this article to be helpful when I was learning authentication.
Might have changed now and somethings might not apply to current version:
http://devdoodles.wordpress.com/2009/02/16/user-authentication-with-django-registration/
(I am not affiliated with this article)




On Sat, May 28, 2011 at 9:07 AM, electrocoder wrote:

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

-- 
You received this message because you are subscribed to the Google 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: @login_required & Redirect...best practice?

2011-05-28 Thread Mick
When I have a view that's @login_required -- and the user isn't logged
> in -- what's the best way to deal with the URL they wanted in the
> first place? Assuming they log in properly and I want to then
> redirect them on to where they intended to go in the first
> place...what's the best practice?
@login_required will redirect to your login page a site the "next" param e.g. 
/accounts/login?next=/where/you/where

The base url for that login page can be set in settings.py as LOGIN_URL
https://docs.djangoproject.com/en/1.3/topics/auth/#the-login-required-decorator


>From the login page you will want to set "next" param in post form used for 
>login (or use the built in form in the auth module)


Mick 

-- 
You received this message because you are subscribed to the Google 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.



Embedded Inline Formsets

2011-05-28 Thread John Anderson
I have 3 Models:

class Workflow(models.Model):
name = models.CharField(max_length=255)
company = models.ForeignKey(Company)

class Meta:
unique_together = ('name', 'company')

class Milestone(models.Model):
workflow = models.ForeignKey(Workflow)
tasks = models.ManyToManyField(Task)

class Task(models.Model):
task = models.CharField(max_length=255)


How could I create a form that allows me to add multiple milestones with 
multiple tasks?


-- 
You received this message because you are subscribed to the Google 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.



choice_set.all()

2011-05-28 Thread bahare hoseini
hi there,
i followed the structure in
https://docs.djangoproject.com/en/dev/intro/tutorial01/  ,every thing was
allright till i wrote the code: >>> "p.choice_set.all()" , then i got
"AttributeError: 'function' object has no attribute choice_set" . :(
can somone 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.