简体   繁体   中英

Get abbreviated column name from Django model field name

I'm having to write a custom where clause for my query. I need to get the column name as it appears in the Oracle table from the fields in the model. I'm looping through the model fields in MyModel._meta.fields and getting the name property. In every case except one the name of the model field is the name of the column. In the exception, the field name is too long for the column, so Django's syncdb gave the column an abbreviated name. How do I get the column name?

My field name: political_contributions_description

The column name: political_contributions_de0ec3

I have tried field.get_attname_column(), as in

for field in MyModel._meta.fields:
    field.get_attname_column()

But that just gives me the following tuple for my field:

('political_contributions_description', 'political_contributions_description')

Btw, an Oracle column over 30 characters will be abbreviated.

尝试...

MyModel._meta.get_field('username').column

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM