https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield
Hope this helps!
Casey
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
poll_key = models.AutoField(primary_key=True)
Now create INSERT statement as follows:
INSERT INTO "poll" ("poll_question", "poll_pub_date") VALUES ('Question!',
'2011-05-27 00:00:00')
With PostgreSQL Schema:
poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
It achieve the goal.
Now question: Documentation indicates that " This is an auto-incrementing
primary key.". This suggest me that Django will create INSERT statement with
poll_key with next sequence value. Am I understanding incorrectly?
Thank you again for your advice in advance.
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" <csgr...@princeton.edu> wrote:
Sent from my iPhone, please excuse any typos
>>> 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
Now everything is happy. Thank you!