Django将selectTlated的OneToOne关系转换为了

时间:2016-06-14 14:55:30

标签: django django-models

我有以下型号,我想执行以下查询:

CREATE TYPE REV_QTY AS INTEGER ARRAY[] ;--ALLOW_ARRAY_VALUE_CHANGES 
CREATE OR REPLACE FUNCTION GET_REV_QTY (IN_IPID INTEGER,QTY_TO_PLACE  
   INTEGER,INITIAL_REV_QTY INTEGER)
RETURNS INTEGER
LANGUAGE SQL
DETERMINISTIC
MODIFIES SQL DATA

--CONTAINS SQL
--RETURNS NULL ON NULL INPUT
NO EXTERNAL ACTION
BEGIN

DECLARE AVAILABLE_REV_QTY REV_QTY;
if exists(AVAILABLE_REV_QTY[IN_IPID]) then
CASE WHEN QTY_TO_PLACE > AVAILABLE_REV_QTY[IN_IPID] THEN 
    SET AVAILABLE_REV_QTY[IN_IPID] = 0
WHEN QTY_TO_PLACE < AVAILABLE_REV_QTY[IN_IPID] AND QTY_TO_PLACE >= 0    
THEN
    SET AVAILABLE_REV_QTY[IN_IPID] =  AVAILABLE_REV_QTY[IN_IPID] -  
QTY_TO_PLACE
END;
     END IF;
 RETURN AVAILABLE_REV_QTY[IN_IPID] ;
 END |

出于某种原因,它不适用于Post.objects.select_related( 'previous_post', 'next_post' ).get(id=some_id) # models.py class Post(models.Model): title = models.CharField(max_length=60, unique=True) description = models.TextField() content = models.TextField() previous_post = models.OneToOneField('self', null=True, blank=True, related_name='next_post', on_delete=models.PROTECT) 参数,因为我收到以下错误:

next_post

理论上我可以不用raise IndexError("Number of args exceeds number of fields") IndexError: Number of args exceeds number of fields生活,但在这种情况下我宁愿不放弃,我真的很好奇我是做错了还是只是一个Django错误。

完整追溯:

select_related

1 个答案:

答案 0 :(得分:2)

它看起来像是Django中的一个错误。我可以在1.8和1.9中重现,但不能在主分支中重现。

执行git bisect,tt似乎已由ticket 26207修复,因此应在Django 1.10中修复。