SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. res = Model._meta.get_field('test_field').verbose_name
  2. res returns  'Test Field'
  3.  
  4. res = Model._meta.get_field('test_field').name
  5. res returns 'test_field'
  6.      
  7. res = Model._meta.get_field('Test Field').name
  8.      
  9. {field.verbose_name: field for field in model._meta._fields()}['Test Field']
  10.      
  11. def get_field_from_verbose(meta, verbose_name):
  12.     try:
  13.         return next(f for f in _meta.get_fields() if f.verbose_name == verbose_name)
  14.     except:
  15.         raise KeyError(verbose_name)
  16.      
  17. get_field_from_verbose(Model._meta, 'Test Field')
  18.      
  19. <input type="checkbox" name="sel_fields[]" value="fieldname1">Verbose fieldname 1<br>
  20. <input type="checkbox" name="sel_fields[]" value="fieldname2">Verbose fieldname 2<br>
  21. <input type="checkbox" name="sel_fields[]" value="fieldname3">Verbose fieldname 3<br>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top