问题描述
我的问题说明了一切。 我已经做了一个控制器来搜索特定模型中的所有记录。
现在,我只想从同一模型中搜索一条记录(按其ID)。
我所有记录的控制者是:
# Get random samples from latent space
z = GAN.random_samples((batch_size,self.latent_dim))
# Augment random samples with the class label (1 for class "fraud") for conditioning
z_conditioned = tf.concat([z,tf.ones((batch_size,1))],axis=1)
# Generate fake data using random samples
x_fake = self.generator(z_conditioned,training=True)
# Calculate the loss and back-propagate
with tf.GradientTape() as c_tape:
c_tape.watch(x_fake)
c_tape.watch(x_real)
# Get the scores for the fake data
output_fake = 0.5 * (self.critic(x_fake) + 1.0)
score_fake = tf.reduce_mean(tf.reduce_sum(output_fake,axis=1))
# Get the scores for the real data
output_real = 0.5 * (self.critic(x_real,training=True) + 1.0)
score_real = tf.reduce_mean((1.0 - 2.0 * y_real) * (output_real[:,0] - output_real[:,1]))
# Calculate the gradient penalty
gp = self.gp_coeff * self.gradient_penalty(batch_size,x_real,x_fake)
# Calculate critic's loss (added 1.0 so its ideal value becomes zero)
c_loss = 1.0 + score_fake - score_real + gp
# Calculate the gradients
c_grads = c_tape.gradient(c_loss,self.critic.trainable_weights)
# back-propagate the loss
self.c_optimizer.apply_gradients(zip(c_grads,self.critic.trainable_weights))
因此,我要添加的内容仅取决于其ID来获得一条记录。
谢谢。
解决方法
sale_rec = request.env['sale.order'].search([('id','=',YOURID)])
或
sale_rec = request.env['sale.order'].browse(YOURID)
均返回所选对象
,首先,像这样更改您的控制器路线:
@http.route(['/get_sales','/get_sales/<int:order_id>'],type='json',auth='user')
这样一来,您现在可以选择是否使用order_id
呼叫路线。
第二,像这样更改您的方法:
def get_sales(self,order_id=None):
现在您可以在方法中添加一些逻辑:
if order_id:
domain = [('id',order_id)]
else:
domain = []
sales_rec = request.env['sale.order'].search(domain)