Answer the question
In order to leave comments, you need to log in
How to make a raw request in Django?
There is this model:
class Orders(models.Model):
id = models.AutoField(primary_key=True)
idhospital = models.IntegerField(blank=True, null=True)
idfinance = models.ForeignKey('RefFinance', db_column='idfinance')
idtest = models.IntegerField(blank=True, null=True)
iddiagprimary = models.IntegerField(blank=True, null=True)
idbiomaterial = models.IntegerField(blank=True, null=True)
iddiagsecondary = models.IntegerField(blank=True, null=True)
ordertype = models.SmallIntegerField(blank=True, null=True)
ordernum = models.CharField(max_length=100, blank=True)
orderdate = models.DateTimeField(blank=True, null=True)
orderprice = models.DecimalField(max_digits=15, decimal_places=2, blank=True, null=True)
dategetbm = models.DateTimeField(blank=True, null=True)
orderready = models.DateTimeField(blank=True, null=True)
dategetorder = models.DateTimeField(blank=True, null=True)
userready = models.CharField(max_length=30, blank=True)
patient = models.CharField(max_length=1024, blank=True)
iin = models.CharField(max_length=1024, blank=True)
dob = models.DateTimeField(blank=True, null=True)
sex = models.SmallIntegerField(blank=True, null=True)
address = models.CharField(max_length=1024, blank=True)
workplace = models.CharField(max_length=1024, blank=True)
depart = models.CharField(max_length=1024, blank=True)
sector = models.CharField(max_length=1024, blank=True)
palata = models.CharField(max_length=1024, blank=True)
numhistory = models.CharField(max_length=100, blank=True)
isdelete = models.BooleanField()
class Meta:
managed = False
db_table = 'orders'
select getordernum(:idvalue)
. IdValue must be passed before the request is executed. order = Orders(patient=fio)
order.idhospital = ...
order. ... = ..
<b>order.ordernum = Orders.GetNewNum</b>
Answer the question
In order to leave comments, you need to log in
well, something like thisPerson.objects.raw('SELECT * FROM myapp_person')
A few minutes later, an insight came from the off-site of the django project
...
class Meta:
managed = False
db_table = 'orders'
def GetNumOrder(self, idOrder):
from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT getordernum(%s) as id", [idOrder])
row = cursor.fetchone()
return row[0]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question