开发者

Django - Creating Models using a factory method

I need to create those three models:

class Model_1(models.Model):
    def get_second_element(self):
        try:
            return Model_1.objects.all()[1]
        except:
            return None

class Model_2(models.Model):
     def 开发者_StackOverflowget_second_element(self):
        try:
            return Model_2.objects.all()[1]
        except:
            return None

class Model_3(models.Model):
     def get_second_element(self):
        try:
            return Model_3.objects.all()[1]
        except:
            return None

How do I write a factory method that gets the name of the model to be created, and creates a model class with that name, and with the function get_second_element that query the DB of this model?

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜