Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#27754 closed Bug (invalid)

Please document that Django models implement __dict__ (or tell me they officially don't)

Reported by: Dave Schweisguth Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


A Django model's __dict__ method is a popular way to get all of its attributes including foreign keys and non-editable fields (which model_to_dict omits):

I can't find documentation that Django models implement __dict__. If it's supported, can it be documented? If it's not supported, oh well.

I care because PyCharm cares:


Change History (3)

comment:1 Changed 4 years ago by Tim Graham

I'm not sure what you mean by "implement __dict__"? Don't all classes have a __dict__ method for storing their attributes? Maybe you can look at the source code for the ModelBase class and answer your own question. If so, please propose some documentation because I'm not sure what your looking for. Thanks.

comment:2 Changed 4 years ago by Carl Meyer

Resolution: invalid
Status: newclosed

__dict__ is not a method, it's an attribute. All Python objects have it (except those that define __slots__). It does not make sense for Django to document that Django models have it, because a) it's a private attribute and an internal implementation detail of Python, that you should probably avoid relying on in your code, although many people use it anyway, and b) it's part of Python, not Django. If we documented every aspect of Python objects that happens to be true for Django objects too (because they are all Python objects), we'd be duplicating a bunch of the Python docs.

I don't know why PyCharm doesn't like you using __dict__; maybe because it's a private double-underscore attribute. You can point them to the Python documentation for it, but there's nothing for Django to document here.

Last edited 4 years ago by Carl Meyer (previous) (diff)

comment:3 Changed 4 years ago by Dave Schweisguth

Totally clear. Thanks to both of you for the correction.

Note: See TracTickets for help on using tickets.
Back to Top