【发布时间】:2018-06-14 12:12:35
【问题描述】:
我正在尝试制作一个应用程序,其中一个人插入某人的 id 和生日日期并输出一些东西。我的 这里的疑问是:使用以下方法查询(来自 oracle)有几个 id 和生日日期:
connection = cx_Oracle.connect(...)
cursor = connection.cursor()
cursor.execute("query")
我的问题是:是否可以将查询中的一些值传递给我的 models.py 文件?例如,在我的“models.py”文件中,我有一个名为“id”的字段,我想将字段“doente”中查询的所有记录作为“id”传递给“models.py”文件。
我的表格是这样的: Form
我的 models.py 文件是:
class PatientTutor(models.Model):
id = models.AutoField(primary_key=True)
username = models.CharField(max_length = 8)
patientID = models.CharField(max_length = 8)
created = models.DateTimeField(auto_now_add = True)
birthday = models.DateField(blank=True, default=None)
birthdayPatient = models.DateField(blank=True, default=None)
字段中的值:“GTS do autorizante”和“Data de nascimento do autorizante”在我的models.py中,字段值:“GTS do autorizado”和“Data de nascimento do autorizado”来从查询。我想将查询中的所有值复制到我的 models.py 文件中,但我不知道这是否可行。
编辑:
我的 views.py 文件如下所示:
def mostraFormTutorPaciente (request):
return render(request, 'CartaoCliente/mostraFormTutorPaciente.html')
def TutorPaciente (request):
if request.method == 'POST':
AutorizanteGTS = PatientTutor.objects.get(id = request.POST['AutorizanteGts'])
NascAutorizante = PatientTutor.objects.get(birthday = request.POST['DtNascAutorizante'])
connection = cx_Oracle.connect("....")
cursor = connection.cursor()
cursor.execute("select t_doente, doente, nome, dt_nasc, telef1, telef2" + \
"from gh.sd_doente where doente<>'" + patientID + \
"'and nvl(flag_anulado, 'N')<>'S' and dt_nasc >= sysdate-18*365 and (trim(telef1) in (" + inClause + ") or trim(telef2) in (" + inClause + "))")
registos =[]
for record in cursor:
registos.append(record)
return render(request, 'CartaoCliente/TutorPaciente.html', )
在这里,我尝试获取来自帖子并位于我的 models.py 中的值,当我连接到 oracle db 时,我尝试获取来自帖子的其他值。
【问题讨论】:
-
这里是不是故意不使用Django的ORM?
-
我不明白这里如何涉及“模型文件”。如果你想在表单中添加数据,你可以在表单类或视图中进行。
-
涉及模型文件,因为应该在“GTS do autorizado”和“Data de nascimento do autorizado”中写入的值在我的models.py文件中。
-
所以你想将数据从 oracle 数据库迁移到支持 django 的数据库?
-
我的目标是在接待员按下按钮时显示一条消息。但是正如我之前解释的那样,她在表格中输入的数据位于不同的地方。我想知道是否可以这样做。类似于我制作的版本。