2012-04-01 32 views

Trả lời

19

Không có sự khác biệt, điều thứ hai ngụ ý sử dụng __exact.

Từ documentation:

For example, the following two statements are equivalent: 
>>> Blog.objects.get(id__exact=14) # Explicit form 
>>> Blog.objects.get(id=14)   
# __exact is implied This is for convenience, because exact 
# lookups are the common case. 
12

Bạn có thể nhìn vào SQL mà Django sẽ thực hiện bằng cách chuyển đổi sở hữu query của queryset để một chuỗi:

>>> from django.contrib.auth.models import User 
>>> str(User.objects.filter(username = 'name').query) 
'SELECT ... WHERE `auth_user`.`username` = name ' 
>>> str(User.objects.filter(username__exact = 'name').query) 
'SELECT ... WHERE `auth_user`.`username` = name ' 

Vì vậy, __exact không có sự khác biệt ở đây.

Các vấn đề liên quan