[Solved]-Django model instance variables for transient use

5👍

That’s an acceptable way of doing it, although you don’t need to initialize it unless there’s a chance you may try to access it when it doesn’t exist. Also, consider if you should be using a property instead.

0👍

Update for Python 3: You can call super() directly without repeating the class name

class MyModel (models.Model):
    name = models.CharField(max_length=300)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.tempvar = ''
👤xjcl

Leave a comment