mirror of
https://github.com/xhongc/music-tag-web.git
synced 2026-04-26 03:31:26 +08:00
feature:first commit
This commit is contained in:
18
component/utils/basic.py
Normal file
18
component/utils/basic.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- 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))
|
||||
Reference in New Issue
Block a user