A simple Django app for command-line searching via the ORM
Project description
django_grepdb is a simple command-line app to provide basic grep-like searching of Django model fields using the ORM. Written to facilitate searching for a tag, filter, named url etc in templates in the database, but can also be used to quickly find model instances from the command line.
Quick start
Add “django_grepdb” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'django_grepdb', )
or, if you have a separate settings file for development in which you extend your global settings, like this:
INSTALLED_APPS = INSTALLED_APPS + ('django_grepdb',)
Run:
$ python manage.py grepdb <pattern> <app_label.Model.field_name>
Usage
Find instances of {% custom_template_tag.*%} in all text fields on the model EmailAction from app sprinkle, show lines containing matches, and generate admin links (if django.contrib.admin is installed):
$ python manage.py grepdb "{% custom_template_tag.*%}" sprinkle.EmailAction <class 'sprinkle.models.EmailAction'> text_field User registered (pk=13) localhost:8000/admin/sprinkle/emailaction/13/ <p>Hi {% custom_template_tag user.get_full_name %},</p> Password reset request (pk=24) localhost:8000/admin/sprinkle/emailaction/24/ <p>Hi, {% custom_template_tag user.get_full_name %}</p>
Options
Options are listed using $ python manage.py grepdb --help but here are some of the things you can do with django_grepdb.
Search multiple models:
$ python manage.py grepdb <pattern> sprinkle.EmailAction cms.MarkdownNode
Specify fields instead of finding all text fields:
$ python manage.py grepdb <pattern> sprinkle.EmailAction.body sprinkle.EmailAction.subject
Find all instances of CharField instead of TextField:
$ python manage.py grepdb <pattern> sprinkle.EmailAction -c
Show the whole field of a match rather than just the line:
$ python manage.py grepdb <pattern> sprinkle.EmailAction -sa
Change the hostname of the admin links:
$ python manage.py grepdb <pattern> sprinkle.EmailAction -l https://dev.example.com
Specify hostname key-value pairs in settings:
DJANGO_GREPDB_SITES = { 'default': 'https://staging.example.com' 'dev': 'https://dev.example.com', } $ python manage.py grepdb <pattern> sprinkle.EmailAction -l dev
Specify preset configurations in settings:
DJANGO_GREPDB_PRESETS = { 'users': dict(identifiers=['auth.user', 'projects.userprofile'], field_type=['CharField', 'TextField'], ignore_case=True), 'templates': dict(identifiers=['sprinkle.EmailAction', 'cms.HTMLNode', 'cms.TextNode', 'cms.MarkdownNode']) $ python manage.py grepdb <pattern> -p templates
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-grep-db-1.1.2.tar.gz
.
File metadata
- Download URL: django-grep-db-1.1.2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6047bdb45f41dc1804ad64261927df0139bc28f61505681a920a36c4122309d9 |
|
MD5 | 6bab93933c3f904654c589591c114f15 |
|
BLAKE2b-256 | fd660f02da6f25e0818939904d19f9c0ff9bd322416ed1b53ac3efc5dc4ee3f6 |
File details
Details for the file django_grep_db-1.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: django_grep_db-1.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac666b697df6ce2848de72f3655fb5be1023d5b26bc726bd9bbe527cf92aa1e |
|
MD5 | 7ccf9d5dd4af7c91d509ddbf6b06cc0a |
|
BLAKE2b-256 | 0dad1d63e0d1281bc9ccb67e3bb65bc0110afdc2c45f72daecb1d64bdc2fd918 |