Sorry for not being this as programming question, but this caught my eye when I was trying to introspect my class objects.
I found this
{'user_id': 1, '_state': <django.db.models.base.ModelState object at 0x10ac2a750>, 'id': 2, 'playlist_id': 8}
What is the role of _state and what ModelState does?
From the Django source code, _state is an instance variable defined in each Model instance that is an instance of
ModelStatethat is defined as:So basically this instance variable is used to know if the
Modelinstance was already written to adb(knowing that Django support multiple db backends) and to hold thedbused, this instance variable attributeaddingis set to false after saving the model instance, and it’s used mostly (as the comment in the code above) for validating if the primary keys is unique.