On 5/8/2009 4:32 PM, Lee Hinde wrote: > Hi; > > I get the error below at a point I'm trying to add 1 to an int field. > I'm understanding the error that django doesn't know what the type is > for sn. > > > Model: > > class Sequence_Number(models.Model): > Sequence_Name = models.CharField(max_length=100) > Next_Sequence_Number = models.IntegerField() > LastUpdate = models.DateField(auto_now = True) > dupefixed = models.DateField(blank=True,null=True) > > def __unicode__(self): > return self.Sequence_Name > > Sequence Number function: > > @transaction.autocommit > def get_SequenceNumber(itemToSequnce): > try: > sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce) > except Sequence_Number.DoesNotExist: > sn = Sequence_Number(Sequence_Name=itemToSequnce) > next_number = sn.Next_Sequence_Number > sn.Next_Sequence_Number += 1 > sn.save() > return next_number > > def buildSlug(slug): > slug = "slug__%s" % (slug) > next_Num = get_SequenceNumber(slug) > slug_with_number = "%s%d" % (slug,next_Num) > return slug_with_number > > > > Traceback: > > File "<console>", line 2, in <module> > File > "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py", > line 314, in save > self.Slug = buildSlug(start) > File > "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py", > line 20, in buildSlug > next_Num = get_SequenceNumber(slug) > File "/Library/Python/2.5/site-packages/django/db/transaction.py", > line 223, in _autocommit > return func(*args, **kw) > File > "/Users/leehinde/Documents/Clients/RecEnrollTNV/RecEnroll/recenrolltnv/../recenrolltnv/recenroll/models.py", > line 14, in get_SequenceNumber > sn.Next_Sequence_Number += 1 > TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
{{{ try: sn = Sequence_Number.objects.get(Sequence_Name=itemToSequnce) except Sequence_Number.DoesNotExist: sn = Sequence_Number(Sequence_Name=itemToSequnce) next_number = sn.Next_Sequence_Number }}} Well, in your except block, you're just instantiating a Sequence_Number object, so of course it doesn't have the Next_Sequence_Number attribute yet. Did you mean to do: {{{ Sequence_Number.objects.create(Sequence_Name=itemToSequnce) }}} ? -- George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---