Django'unicode'对象不可调用

时间:2014-02-24 11:55:38

标签: python django unicode

subjects_db = UTMESubjects.objects.values_list("List_of_Subjects", flat=True).order_by('id')[:]
        #return HttpResponse(subjects_db)
        for subjects in subjects_db: #inspects available subjects in db
            if subject in subjects:
                db_table = subject
                data = subject(
                        Questions = Question,
                        Options_1 = option1,
                        Options_2 = option2,
                        Options_3 = option3,
                        Options_4 = option4,
                        Options_5 = option4,
                        Answers = answer,
                        Difficulty_Level = difficulty_level,
                        Question_Year = question_year,
                        Diagram = "null",
                        Status = value,
                        )
                data.save()

我一直得到TypeError'unicode'对象不可调用。我尝试在提交到数据库表时传递subject的值作为表名。这是为了允许通过变量主题的不同值多次使用代码。

1 个答案:

答案 0 :(得分:0)

变量主题(我想是一个字符串)和用于创建模型/对象的可调用主题之间存在冲突。本地人可能会重写主题类的输入。

我会使用Subject作为python约定的模型名称。如果确实需要,请更改本地变量主题名称或使用其他名称导入主题类。

import subject as subject_class
data = subject_class(
                    Questions = Question,
                    Options_1 = option1,
                    Options_2 = option2,
                    Options_3 = option3,
                    Options_4 = option4,
                    Options_5 = option4,
                    Answers = answer,
                    Difficulty_Level = difficulty_level,
                    Question_Year = question_year,
                    Diagram = "null",
                    Status = value,
                    )