mirror of
https://github.com/xhongc/music-tag-web.git
synced 2026-02-03 10:13:30 +08:00
19 lines
442 B
Python
19 lines
442 B
Python
# -*- coding: utf-8 -*-
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
def tuple_choices(tupl):
|
|
"""从django-model的choices转换到namedtuple"""
|
|
return [(t, t) for t in tupl]
|
|
|
|
|
|
def dict_to_namedtuple(dic):
|
|
"""从dict转换到namedtuple"""
|
|
return namedtuple("AttrStore", list(dic.keys()))(**dic)
|
|
|
|
|
|
def choices_to_namedtuple(choices):
|
|
"""从django-model的choices转换到namedtuple"""
|
|
return dict_to_namedtuple(dict(choices))
|