Opened 8 years ago

Closed 8 years ago

Last modified 8 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

Description

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): http://stackoverflow.com/a/29088221/634576

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: https://youtrack.jetbrains.com/issue/PY-22313

Thanks!

Change History (3)

comment:1 by Tim Graham, 8 years ago

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 by Carl Meyer, 8 years ago

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 at https://docs.python.org/3/library/stdtypes.html#object.__dict but there's nothing for Django to document here.

Version 0, edited 8 years ago by Carl Meyer (next)

comment:3 by Dave Schweisguth, 8 years ago

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

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