[Answer]-Django: Passing arguments to ModelField at runtime

1👍

You don’t need to do anything to pass the xyz variable on — it is an instance variable on the model, so it is already present in the model_instance variable that gets passed to pre_save()

class MyField(models.TextField):

    def pre_save(self, model_instance, add):
        ...
        # Access model_instance.xyz here
        ...
        # Call the superclass in case it has work to do
        return super(MyField, self).pre_save(model_instance, add)

Leave a comment