[Answer]-Getting value of foreign key

1👍

From the docs:

Behind the scenes, Django appends "_id" to the field name to create its database column name.

alpha.asampleID_id = self.pk

This is why having a suffix of “ID” is inappropriate.

0👍

From the given error message, it looks like you are trying to save a relationship. You should pass the actual object, not its primary key.

def save(self, *args, **kwargs):
    is_new = self.pk is None
    super(Sample, self).save(*args, **kwargs)
    if is_new:
        alpha = AnotherSample()
        alpha.asampleID =  self
        alpha.say = "Lolz"
        alpha.save()
👤pram

Leave a comment