Field map for models

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
################################################################################
try:
    import models as this_db
    for item in dir(this_db):
        try:
            obj = getattr(this_db, item)
            if type(obj) == models.base.ModelBase:
                fields = dict((f.name, f) for f in obj._meta.fields)
                setattr(obj._meta, 'field_map', fields)
        except:{}
except:{}
################################################################################

More like this

  1. User Profile minimal code by Natim 1 year, 9 months ago
  2. ImageField with per user folder by pigletto 5 years, 4 months ago
  3. Dynamic tabular inlines with optional drag-n-drop sorting by Aneon 4 years ago
  4. Database file storage by powerfox 4 years, 3 months ago
  5. slug filename by willhardy 3 years, 10 months ago

Comments

Gulopine (on December 26, 2007):

Or you could just use _meta.get_field("name"), which has been available since Django's initial public release.

#

(Forgotten your password?)