[Answer]-Dropdown choice argument to a db function inside python script on the fly

1👍

✅

override your model’s save method to do custom actions before the data is saved. https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

def get_direction_db(self.nod_id1, self.nod_id2):
    cursor = connection.cursor()
    cursor.execute("SELECT GETDIRECTIONDB(262,265) from sys.dual")
    result = cursor.fetchall()
    return result[0]  # or whatever

class MyModel(models.Model):
    nod_id1 = models.ForeignKey('Eonodes',..)
    nod_id2 = models.ForeignKey('Eonodes',..)
    directiondb = models.IntegerField()

    def save(self, *args, **kwargs):
        self.directiondb = get_direction_db(self.nod_id1, self.nod_id2)
        super(MyModel, self).save(*args, **kwargs)

Leave a comment