diff -rduP -x .svn -x '*.pyc' django-trunk/tests/modeltests/custom_sequence/models.py django-new/tests/modeltests/custom_sequence/models.py --- django-trunk/tests/modeltests/custom_sequence/models.py 1970-01-01 01:00:00.000000000 +0100 +++ django-new/tests/modeltests/custom_sequence/models.py 2008-02-26 15:01:12.000000000 +0100 @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +""" +XX. Using a custom incrementor sequence for an AutoField + +By default, Django generates the name of the incrementor sequence +automatically. But you can override this behavior by explicitly adding +``sec_name`` to the AutoField. +""" + +from django.db import models + +class Human(models.Model): + id = models.AutoField(seq_name='global_id_seq') + name = models.CharField(max_length=64) + + def __unicode__(self): + return self.name + +class Animal(models.Model): + id = models.AutoField(seq_name='global_id_seq') + name = models.CharField(max_length=64) + + def __unicode__(self): + return self.name + +class Voter(Human): + name = models.CharField(max_length=64) + + def __unicode__(self): + return self.name + +__test__ = {'API_TESTS':""" +>>> jane = Human(name="Jane Doe") +>>> jane.save() +>>> Human.objects.all() +[] + +>>> jane.id +1 + +>>> bowser = Animal(name="Ridgemont von Fjausterhofen III aka. Bowser") +>>> bowser.save() +>>> Animal.objects.all() +[] + +>>> bowser.id +2 + +>>> mary = Voter(name="Mary Sue Heinlein") +>>> mary.save() +>>> Voter.objects.all() +[] + +>>> mary.id +3 + +# This belongs in an inheritance test +#>>> Human.objects.all() +#[, ] + +>>> Human.objects.get(pk=1) + +>>> Human.objects.get(pk=2) +Traceback (most recent call last): + ... +DoesNotExist: Human matching query does not exist. + +# Jane Doe was identified and got a real name +>>> ana = Human.objects.get(pk=1) +>>> ana.name = 'Anastasia Romanova' +>>> ana.save() +>>> ana.id +1 + +# Mary got a friend +>>> kim = Voter(name="Kim Possible") +>>> kim.save() +>>> Voter.objects.all() +[, ] +>>> kim.id +4 +"""}