장고 - Django 1.7 Custom Lookups


참고 : https://docs.djangoproject.com/en/1.7/howto/custom-lookups/




https://docs.djangoproject.com/en/1.7/ref/models/lookups/


A lookup expression consists of three parts:


Fields part (e.g. Book.objects.filter(author__best_friends__first_name...);

Transforms part (생략가능) (e.g. __lower__first3chars__reversed);

A lookup (e.g. __icontains) that, if omitted, defaults to __exact.


==> 필드명__(트랜스폼)__lookup 형태를 가진다. 




https://docs.djangoproject.com/en/1.7/howto/custom-lookups/


A simple lookup example

Author.objects.filter(name__ne='Jack')

--> "author"."name" <> 'Jack'




A simple transformer example

https://docs.djangoproject.com/en/1.7/howto/custom-lookups/#a-simple-transformer-example

Experiment.objects.filter(change__abs=27)

-->  SELECT ... WHERE ABS("experiments"."change") = 27


Experiment.objects.filter(change__abs__lt=27)

--> SELECT ... WHERE ABS("experiments"."change") < 27




Posted by 자유프로그램