I want to generate an unique string in my django1.6 application. For that I want to concatenate the primary key (autofield) with the string. My code is
class Complaints(models.Model):
gid = models.AutoField(primary_key=True)
complaint_no = models.CharField(max_length=50)
status = models.IntegerField(default=0,blank=False,null=False)
def __str__(self):
return ('%s %s' % (self.gid, self.complaint_no))
def save(self, force_insert=False, force_update=False):
self.complaint_no = '%s%d' % (self.complaint_no,self.gid)
super(Complaints, self).save(force_insert, force_update)
class Meta:
db_table = 'complaints'
verbose_name = "complaints"
But I got the error message as
TypeError at /callcentre/register/
%d format: a number is required, not NoneType
Please help me to solve this error!