Skip to main content

Django model properties that are also lookup expressions.

Project description

Django Lookup Property

Coverage Status GitHub Workflow Status PyPI GitHub GitHub Last Commit GitHub Issues Downloads Python Version

pip install django-lookup-property

Documentation: https://mrthearman.github.io/django-lookup-property/

Source Code: https://github.com/MrThearMan/django-lookup-property/

Contributing: https://github.com/MrThearMan/django-lookup-property/blob/main/CONTRIBUTING.md


Django model properties that are also lookup expressions.

from lookup_property import lookup_property
from django.db import models
from django.db.models import Value
from django.db.models.functions import Concat

class Student(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)

    @lookup_property
    def full_name():
        return Concat("first_name", Value(" "), "last_name")
>>> from myapp.models import Student
>>> from lookup_property import L
>>>
>>> Student.objects.create(first_name="John", last_name="Doe")
>>> student = Student.objects.filter(L(full_name="John Doe")).first()
>>>
>>> student.full_name
'John Doe'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_lookup_property-0.1.4.tar.gz (20.0 kB view hashes)

Uploaded Source

Built Distribution

django_lookup_property-0.1.4-py3-none-any.whl (27.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page