Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102187
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: class attribute |
| Date | 2016-01-29 01:56 +1100 |
| Message-ID | <mailman.57.1453993003.2338.python-list@python.org> (permalink) |
| References | <56aa1474$0$27833$426a74cc@news.free.fr> <n8d6mm$i5k$1@ger.gmane.org> |
On Fri, Jan 29, 2016 at 12:56 AM, jmp <jeanmichel@sequans.com> wrote: > My guess is that models.Model has a metclass. Without going too much int > details, the metaclass may change the class structure when it's created. > > django is very specific and very database oriented. > > " > article = Article(titre="Bonjour", auteur="Maxime") > article.contenu = "Les crêpes bretonnes sont trop bonnes !" > " > > this is probably the wrong way to assign a value to 'contenu'. You should > have a look at django help files, from what I remember it's very well > documented with a lot of examples. > I suspect Django's using the descriptor protocol or other magic here. SQLAlchemy works in a similar way; when you create the class, you put a bunch of attributes on it to specify columns, and then you can simply assign to those attributes on an instance to set the values for a row to be saved to the database. As Todd explains in further detail, the metaclass gets to do whatever it likes. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
class attribute "ast" <nomail@invalid.com> - 2016-01-28 14:15 +0100 Re: class attribute jmp <jeanmichel@sequans.com> - 2016-01-28 14:56 +0100 Re: class attribute Todd Dembrey <todd.dembrey@gmail.com> - 2016-01-28 14:13 +0000 Re: class attribute "ast" <nomail@invalid.com> - 2016-01-28 15:24 +0100 Re: class attribute Chris Angelico <rosuav@gmail.com> - 2016-01-29 01:56 +1100 Re: class attribute Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-28 11:04 -0500
csiph-web