在peewee模型中动态定义类的名称 [英] Dynamically define name of class in peewee model

查看:144
本文介绍了在peewee模型中动态定义类的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用字符串动态分配类名.

I'm trying to assign a class name dynamically using a string.

很像这样...

classname='cats'

class classname(peewee.Model):

Peewee 似乎不认为我应该能够做到这一点,而且我在寻找动态定义类名的方法时遇到了很多麻烦.

Peewee doesn't seem to think I should be able to do this and I'm having a lot of trouble finding a way to define the class name dynamically.

帮助!

推荐答案

如果需要控制表名,可以这样做:

If you need to control the table name, you can do:

 class MyModel(Model):
     whatever = CharField()

     class Meta:
         db_table = 'my_table_name'

这篇关于在peewee模型中动态定义类的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆