1👍
You can also dynamically build a dict from your dict
(you shouldn’t use a builtin name as identifier BTW) and pass it as kwargs to meter1()
(you shouldn’t use all-lowers as class names BTW). Oh and yes: you may want to have a look at modelmanager.create()
too.
def import_data():
fieldmap = {"1":"U1N","2":"U2N",}
fieldindex = "1"
kw = {fieldmap[fieldindex]: 1.0}
# either:
q = Meter1(**kw)
q.save()
# or:
q = Meter1.objects.create(**kw)
- [Answer]-Incorrect Django URL pattern match for 2 views with the same URL structure?
- [Answer]-Tastypie – Should method be in UserResource or ThreadResource?
- [Answer]-[django+mysql]MySQLdb.connect works well, but cannot connect mysql via settings.py
- [Answer]-Django model for time-table like objects
- [Answer]-Django Cannot resolve keyword 'items' into field. Choices are: id, name
Source:stackexchange.com