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
- Single sign on to Django site via remote Active Directory
- Serving static files with Nginx + Gunicorn + Django
- Django: Limiting the number of relationships in a OnetoMany relationship
- Django website, basic 2d python game
- Htaccess on heroku for django app
Source:stackexchange.com