I have the following model in which one the fields is based on other fields (similar to this):
from django.db import models
class Model_Model01(models.Model):
code_01 = models.CharField(max_length = 2, null = False, blank = False)
code_02 = models.CharField(max_length = 3, null = False, blank = False)
code_combined = models.CharField(max_length = 6, null = True, blank = False, primary_key = False)
def save(self, *args, **kwargs):
self.code_combined = "{}.{}".format(self.code_01, self.code_02)
super(Model_Model01, self).save(*args, **kwargs)
def __unicode__(self):
return self.code_combined
I would like to set the primary_key of code_combined field as True after overriding the save method so I can use it as a foreignkey on other model. Is there a way to do this?