Skip to main content

Django field that combines multiple fields into a search-indexed concatenated value

Project description

django-searchfield

Django field that concatenates multiple fields into a search-indexed string.

Purpose

Create a full-text search field by combining multiple model fields. Values are concatenated with _ by default for simple startswith / icontains queries.

Installation

pip install django-searchfield

Quick Start

Using SearchField directly

from django.db import models
from searchfield import SearchField

class Product(models.Model):
    name = models.CharField(max_length=100)
    code = models.IntegerField()
    created_date = models.DateField()

    search = SearchField(source_fields=["name", "code", "created_date"])

Using the decorator

from django.db import models
from searchfield import add_searchfield

@add_searchfield(search=["title", "category"])
class Article(models.Model):
    title = models.CharField(max_length=200)
    category = models.CharField(max_length=50)
    content = models.TextField()

Path resolution (relations, JSON)

class Creditor(models.Model):
    contact = models.ForeignKey(Contact, ...)
    contact_data = models.JSONField()  # {"firstname": "...", "lastname": "..."}

    search = SearchField(source_fields=[
        "name",
        "contact.lastname",       # relation
        "contact_data.firstname", # JSON keys
    ])

Features

  • Automatic generation: Values are generated automatically before saving
  • Path resolution: Source paths support dotted notation (name, contact.lastname, contact_data.firstname for JSON)
  • Search indexing: Normalized values (NFKD, lowercase) concatenated with _ for startswith/icontains
  • Duplicate removal: Duplicate values from source fields are removed before concatenation
  • Type formatting: Automatically formats dates, numbers, booleans
  • Read-only: Field is editable=False
  • db_index=True: Indexed for search performance
  • unique=False: Not unique by default (allows homonyms); pass unique=True to enforce

Field Properties

  • editable=False: Read-only
  • blank=True, null=True: Optional (empty if all source fields are empty)
  • db_index=True: Indexed for search queries
  • unique=False: Homonyms allowed by default

Development

./service.py dev install-dev
./service.py dev test

License

MIT

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_searchfield-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_searchfield-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file django_searchfield-0.1.1.tar.gz.

File metadata

  • Download URL: django_searchfield-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_searchfield-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e29c222a7aebae21bfbff33dd10448ba6362ac3daebfa5d378b7ef68ae67c940
MD5 d676c350f0b08fd59016b561d3c17dec
BLAKE2b-256 5c7d2279aa90aff8a52d06d97938eee0126dac29f2ea6a7214271766be0c8e90

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_searchfield-0.1.1.tar.gz:

Publisher: release.yml on octolo/django-searchfield

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_searchfield-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_searchfield-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d379067cc97d185828a7aa0b56d14dcbbafaea14425538e009d1db0035010ae
MD5 e7fdfbee2ace4166f607b0fb45c54cb3
BLAKE2b-256 c6148dccc842422d61c56671349ccc0aed9d55b39d061c2ecc89d7f752624757

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_searchfield-0.1.1-py3-none-any.whl:

Publisher: release.yml on octolo/django-searchfield

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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