
That is true, but of course in Django the field is an object, and it is the object that knows it's name. There is nothing to stop you declaring a field in a model called 'person_name' but also doing this in the code : user_name = instance.person_name In Django the user_name variable will only have the name 'person_name', but not user_name, as the field objects need to know their names on the model (and their names on the views/forms). ------ Original Message ------ From: "Rene Nejsum" <rene@pylots.com> To: python-ideas@python.org Sent: Saturday, 4 Nov, 23 At 08:13 Subject: [Python-ideas] Re: Extract variable name from itself A little late, but the requirement to "Extract variable name from itself" is widely used in Django. Each field in a Django model, knows it's own variable name user_name = models.CharField(...) The instance of CharField knows that it's variable name is "user_name", so that it can name the row in the database the same. On startup Django runs through the Model class searching for instances of Field and gets the name that way _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SJUKWX... Code of Conduct: http://python.org/psf/codeofconduct/ -- <br>Anthony Flury<br>anthony.flury@btinternet.com