如何对作为函数参数传递的django模型进行查询

时间:2017-05-13 15:21:03

标签: django function django-models django-orm

定义我的模型

class Model1(models.Model):
    description = models.TextField()
    some_attribute_1 = models.IntegerField

class Model2(models.Model):
    description = models.TextField()
    some_attribute_2 = models.CharField(max_length=10)

我想构建一个函数:

def my_function(model, desc):
    return model.objects.filter(description = desc)

并将其用作

str1 = my_function(Model1, "some description")
str2 = my_function(Model2, "some description")

0 个答案:

没有答案