samedi 23 février 2019

generate random value form other field value in Django

I have a booking system for bank line : this is my model for the customer:

class Customer(models.Model):
customer_bank        = models.ForeignKey('Bank', on_delete=models.SET_NULL,related_name='coustmer_bank' ,null=True)
customer_branch      = models.ForeignKey('Branch', on_delete=models.SET_NULL,related_name='coustmer_branch',null=True)
booking_id           = models.CharField(max_length=120, blank= True,default=increment_booking_number)
identity_type        = models.ForeignKey('IdentityType',on_delete=models.SET_NULL,related_name='identity_type',null=True)
identity_or_passport_number   = models.CharField(max_length=20)
bank_account_no      = models.CharField(max_length=15)
Done                 = models.BooleanField(default=False)
booking_date_time    = models.DateTimeField(auto_now_add=True, auto_now=False)
Entrance_date_time   = models.DateTimeField(auto_now_add=False, auto_now=True)# Must be modified to work with Entrance Date and Time

def __str__(self):
    return self.booking_id

I need to generate a random value for booking_id field depends on bank_number and the branch_number and the Customer id so how can I do that? help please




Aucun commentaire:

Enregistrer un commentaire