2012-04-01 8 views

risposta

19

Non c'è alcuna differenza, la seconda implica l'utilizzo di __exact.

Dal 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

Potete guardare l'SQL che Django eseguirà convertendo proprietà del set di query query a una stringa:

>>> 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 ' 

Quindi __exact non fa alcuna differenza qui.

Problemi correlati