소스 검색

Fixed #27414 -- Doc'd that F() expressions on relations return pk values.

Jop Reyntjes 8 년 전
부모
커밋
f8fab6f902
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      docs/ref/models/expressions.txt

+ 9 - 0
docs/ref/models/expressions.txt

@@ -214,6 +214,15 @@ directly support ``output_field`` you will need to wrap the expression with
         expires=ExpressionWrapper(
             F('active_at') + F('duration'), output_field=DateTimeField()))
 
+When referencing relational fields such as ``ForeignKey``, ``F()`` returns the
+primary key value rather than a model instance::
+
+    >> car = Company.objects.annotate(built_by=F('manufacturer'))[0]
+    >> car.manufacturer
+    <Manufacturer: Toyota>
+    >> car.built_by
+    3
+
 .. _func-expressions:
 
 ``Func()`` expressions