After creating a model object I would like to use a post_save
signal to populate another model field in the same object with the ID and other values.
But the real question here is, how do i access the field from the instance? nothing worked
Example:
User creates an object -> id
of the object is 93 -> I would like to add #00093
as value of another field in the same object.
models.py
class Ticket(models.Model):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
designation = models.CharField(max_length=255, blank=True, null=True)
summary = models.CharField(max_length=255)
signals.py
@receiver(post_save, sender=Ticket)
def ticket_designation(sender, instance, **kwargs):
instance.designation = "#" + "000" + str(instance.id)
print("Ticket" + instance.designation + " was created.")