Skip to main content

Model inspection for Django

Project description

Django-inspect-model

Build Status

Django-inspect-model is a model inspection utility for Django. It allows you to easily list all available “items” on a model, and get their value.

An item is either:

  • a django field (standard field or relation field)

  • a standard attribute

  • a method that only takes one attribute: ‘self’

  • a property

The code is generic enough to be applied on just any python object, so Django isn’t a requirement. However, it was tailored towards Django models.

Install

Using pip:

pip install django-inspect-model

Usage

Instantiate inspect_model.InspectModel with your model class or instance, and profit.

>>> from django.contrib.comments.models import Comment
>>> from inspect_model import InspectModel
>>> im = InspectModel(Comment)
>>> im.fields
['comment', 'id', 'ip_address', 'is_public', 'is_removed', 'object_pk',
'submit_date', 'user_email', 'user_name', 'user_url']
>>> im.relation_fields
['content_type', 'site', 'user']
>>> im.many_fields
['flags']
>>> im.attributes
[]
>>> im.methods
['get_as_text', 'get_content_object_url']
>>> im.properties
['email', 'name', 'pk', 'url', 'userinfo']
>>> im.items
['comment', 'content_type', 'email', 'flags', 'get_as_text',
'get_content_object_url', u'id', 'ip_address', 'is_public', 'is_removed',
'name', 'object_pk', 'pk', 'site', 'submit_date', 'url', 'user',
'user_email', 'user_name', 'user_url', 'userinfo']

Hacking

Setup your environment:

git clone https://github.com/magopian/django-inspect-model.git
cd django-inspect-model

Hack and run the tests using Tox to test on all the supported python and Django versions:

make test

To build the docs:

make docs

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-inspect-model-0.6.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

django_inspect_model-0.6-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-inspect-model-0.6.tar.gz.

File metadata

File hashes

Hashes for django-inspect-model-0.6.tar.gz
Algorithm Hash digest
SHA256 9b48de70db5210e960943a0d167708b3f70a8a83c27c2df071f03d3652068742
MD5 753b086295efcd8cf60ab5f2919fadb6
BLAKE2b-256 5246fbf783cbc5a6d7bfa0291918b1297ddf05879f39bd8823db51fe7d332061

See more details on using hashes here.

File details

Details for the file django_inspect_model-0.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_inspect_model-0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e494afc2b8c05b166177f0415933876d8dde6f1ebd881504c827cb0cc48ab91d
MD5 268fce083d83cd77e5face29ebd13899
BLAKE2b-256 c456e665e81bcd4b435d4ab67f03875ae2c9f0041d3ef227f04b433c329866ae

See more details on using hashes here.

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