[Python-ideas] Re: Extract variable name from itself

2023-11-08 Thread anthony.flury via Python-ideas
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" 
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-le...@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/SJUKWXOJY6CLPAVTH4NZHDNFXND6USDM/


Code of Conduct: http://python.org/psf/codeofconduct/



-- Anthony Fluryanthony.fl...@btinternet.com
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/QN7Y4JQIE2MLPS3THW5GBXDAB673FUV5/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Extract variable name from itself

2023-11-08 Thread Rene Nejsum
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-le...@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/SJUKWXOJY6CLPAVTH4NZHDNFXND6USDM/
Code of Conduct: http://python.org/psf/codeofconduct/