{ "info": { "author": "Mike Johnson", "author_email": "mike@publicstatic.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: zlib/libpng License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7" ], "description": "================\n Django-Modeler\n================\n\nDjango-modeler generates ORM code from an object instance, optionally including foreign key dependencies.\n\n----------\n Example\n----------\n\nModeler adds a management command to Django:\n\n::\n\n $ python manage.py modeler myapp.testmodel\n from myapp.models import TestModel\n from django.contrib.auth.models import User\n from decimal import Decimal\n import datetime\n\n\n user1, created = User.objects.get_or_create(\n id=1,\n username=u'mike',\n first_name=u'',\n last_name=u'',\n email=u'mike@localhost.com',\n password=u'sha1$911c9$614a16c3c074f2972e14efbe97f4fa92b266b93f',\n is_staff=True,\n is_active=True,\n is_superuser=True,\n last_login=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n date_joined=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n )\n\n testmodel1, created = TestModel.objects.get_or_create(\n id=1,\n user=user1,\n )\n\nAs requested, modeler found the TestModel instances and generated ORM code to recreate it (if it doesn't already\nexist). Modeler also generated code for the User object since it was referenced by TestModel.\n\n----------\n Why?\n----------\n\nThis is a much nicer way of including test data. You probably already have a working site and some data for\nproduction, but ``dumpdata`` will serialize the data for an entire app. That's too much just to write a quick test!\n\nMany people end up with an old, out-of-date copy of their production data in their test fixtures that nobody dares to change.\nAnd because fixtures can be a pain to keep up to date with site changes, it's common place to see a bunch of tests\ndepend on the same fixtures. Sometimes entire projects will depend on just one or two fixtures.\n\nUnfortunately, if a refactor needs a fixture change due to model changes, changing the fixture could cause other tests to fail\nthat are unrelated to the refactor. Worse, it's difficult to edit the json directly, cumbersome to load and modify\nit, and refactoring tools won't update fixtures.\n\nInstead, it's better to have each test use it's own data unrelated to other apps in the project. Django-modeler\nmakes this easier to handle by generating Django ORM code that can be included in tests (or for other purposes).\n\n----------\n Install\n----------\n\nTo get this awesome for your very own, ``pip install django-modeler`` or ``python setup.py install`` from source.\n\nNext, add ``django_modeler`` to your INSTALLED_APPS in ``settings.py``, like so:\n\n::\n\n INSTALLED_APPS = (\n # other apps\n 'django_modeler',\n # other apps\n )\n\n----------\n USAGE\n----------\n\nModeler supports a few command line options:\n\n::\n\n Usage: manage.py modeler [options] \n\n Writes data to ORM code to the console\n\n Options:\n -v VERBOSITY, --verbosity=VERBOSITY\n Verbosity level; 0=minimal output, 1=normal output,\n 2=all output\n --settings=SETTINGS The Python path to a settings module, e.g.\n \"myproject.settings.main\". If this isn't provided, the\n DJANGO_SETTINGS_MODULE environment variable will be\n used.\n --pythonpath=PYTHONPATH\n A directory to add to the Python path, e.g.\n \"/home/djangoprojects/myproject\".\n --traceback Print traceback on exception\n -f FILTER, --filter=FILTER\n Filter objects\n -e EXCLUDE, --exclude=EXCLUDE\n Exclude objects\n -r RELATED, --related=RELATED\n number of object relationship levels to pull (does not\n resolve circular references).\n --exclude-related=EXCLUDE_RELATED\n exclude a package or specific model when searching for\n related objects (format: app_label or app_label.model)\n --exclude-field=EXCLUDE_FIELD\n exclude field types from ever appearing in output\n (format: app_label or app_label.model)\n --version show program's version number and exit\n -h, --help show this help message and exit\n\nMost important is the name of the model to start with. Modeler works by starting at an object instance and building\na dependency tree from that point. The tree can have many starting points, or it can start from a single instance.\nThe easiest way to filter for a single object is by using the `-f` filter. For example:\n\n::\n\n $ python manage.py modeler auth.user -f pk=1\n from django.contrib.auth.models import User\n from decimal import Decimal\n import datetime\n \n user1, created = User.objects.get_or_create(\n id=1,\n username=u'mike',\n first_name=u'',\n last_name=u'',\n email=u'mike@localhost.com',\n password=u'sha1$911c9$614a16c3c074f2972e14efbe97f4fa92b266b93f',\n is_staff=True,\n is_active=True,\n is_superuser=True,\n last_login=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n date_joined=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n )\n\n\nThe `-f filter` and `-e exclude` options are fed directly to Django's ORM filter and exclude methods on QuerySet_\nand support the same options.\n\n.. _QuerySet: https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.filter\n\nWith the `-r related` option, Modeler will attempt to also use ForeignKey references in it's output. In the example above,\npulling the auth.user instance only found a single object to serialize. But given the same command with a related depth\nof 1, Modeler will find more objects that reference this particular user instance:\n\n::\n\n $ python manage.py modeler auth.user -f pk=1 -r1\n from django.contrib.auth.models import User\n from myapp.models import TestModel\n from decimal import Decimal\n import datetime\n\n\n user1, created = User.objects.get_or_create(\n id=1,\n username=u'mike',\n first_name=u'',\n last_name=u'',\n email=u'mike@localhost.com',\n password=u'sha1$911c9$614a16c3c074f2972e14efbe97f4fa92b266b93f',\n is_staff=True,\n is_active=True,\n is_superuser=True,\n last_login=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n date_joined=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n )\n\n testmodel1, created = TestModel.objects.get_or_create(\n id=1,\n user=user1,\n )\n\nWith `-r2` Modeler will find another object instance that depends on the TestModel in the above:\n\n::\n\n $ python manage.py modeler auth.user -f pk=1 -r2\n from myapp.models import RelatedToTestModel\n from django.contrib.auth.models import User\n from myapp.models import TestModel\n from decimal import Decimal\n import datetime\n\n\n user1, created = User.objects.get_or_create(\n id=1,\n username=u'mike',\n first_name=u'',\n last_name=u'',\n email=u'mike@localhost.com',\n password=u'sha1$911c9$614a16c3c074f2972e14efbe97f4fa92b266b93f',\n is_staff=True,\n is_active=True,\n is_superuser=True,\n last_login=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n date_joined=datetime.datetime(2011, 8, 18, 20, 39, 14, 352576),\n )\n\n testmodel1, created = TestModel.objects.get_or_create(\n id=1,\n user=user1,\n )\n\n relatedtotestmodel1, created = RelatedToTestModel.objects.get_or_create(\n id=1,\n test_model=testmodel1,\n name=u'related_one',\n )\n\n relatedtotestmodel2, created = RelatedToTestModel.objects.get_or_create(\n id=2,\n test_model=testmodel1,\n name=u'related_two',\n )\n\nOther options are ``--exclude-related`` and ``--exclude-field``. These both require an app_label.model argument.\nExclude related will ignore models found that match the app_label or model name when Modeler is searching\nforeign key relationships, like in the above example both TestModel and RelatedToTestModel were found during the related\nsearch.\n\nUsing ``--exclude-field`` prevents a model or app from ever showing up in the output, regardless of how it was found.\n\n------------\n LIMITATIONS\n------------\n\nAt this time, Modeler does not attempt to resolve circular dependencies when using `-r`. It may be necessary to limit\nthe depth that Modeler will travel in order to avoid an exception because of the model dependencies.\n\n-------------------------\n WHAT CAN I DO WITH IT?\n-------------------------\n\nThe original use case was to create test data. Use Modeler to create a `data.py` file in a tests folder:\n\n::\n\n $ python manage.py modeler auth.user -f pk=1 -r2 > tests/data.py\n\n`data.py` probably needs a `load()` method. The tests_ are a good example of this style usage.\n\n.. _tests: https://github.com/mrj0/django-modeler/blob/master/tests/myapp/tests/data.py\n\nNext, in the test that requires this data, add a setupUp method to load and use the data:\n\n::\n\n def setUp(self):\n data.load()\n\n\n------------\n SUPPORT\n------------\n\nPlease use Github_.\n\n.. _Github: https://github.com/mrj0/django-modeler", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mrj0/django-modeler", "keywords": null, "license": "zlib/libpng", "maintainer": null, "maintainer_email": null, "name": "django-modeler", "package_url": "https://pypi.org/project/django-modeler/", "platform": "OS Independent", "project_url": "https://pypi.org/project/django-modeler/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mrj0/django-modeler" }, "release_url": "https://pypi.org/project/django-modeler/0.5/", "requires_dist": null, "requires_python": null, "summary": "Generate django ORM code from object instances (great for testing)", "version": "0.5" }, "last_serial": 790104, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "5d717e74090769233a3c20bac8004e0a", "sha256": "21b8d911ec72a6f616a56650bb6c5db013f5d6d7504dc9e1285f6bfa120a1fee" }, "downloads": -1, "filename": "django-modeler-0.1.tar.gz", "has_sig": false, "md5_digest": "5d717e74090769233a3c20bac8004e0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11130, "upload_time": "2011-08-20T21:37:43", "url": "https://files.pythonhosted.org/packages/4b/b4/f1806e70b8ca76340c00edb8074caa025ee46c217977207e1ae94d87fe56/django-modeler-0.1.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "152babc66b409857aa4b93f3100e3b4a", "sha256": "c003feb825908e2076cfbce6671c59a621d6269e278f7ca3b7c3fd6f1b573892" }, "downloads": -1, "filename": "django-modeler-0.2.1.tar.gz", "has_sig": false, "md5_digest": "152babc66b409857aa4b93f3100e3b4a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11451, "upload_time": "2011-08-25T02:08:01", "url": "https://files.pythonhosted.org/packages/70/f9/82d277da58fa0cb28be7f9eded33f555e8fe0a4afa20f08f52c1726d9906/django-modeler-0.2.1.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "b3133ae2beae4df62ec8a378a8b5f47f", "sha256": "f64a5cbe468af819a8c232abbcfffbc0193e797224f5eb5b6c64285f6e73faa4" }, "downloads": -1, "filename": "django-modeler-0.3.tar.gz", "has_sig": false, "md5_digest": "b3133ae2beae4df62ec8a378a8b5f47f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11461, "upload_time": "2011-08-25T03:44:14", "url": "https://files.pythonhosted.org/packages/c0/10/e194acca268093ca9e261f47878aa6ecd6b5800094c306e7e7a7a63110e5/django-modeler-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "b9d95ec85f39d3a95b7bad0a347e12fc", "sha256": "f687467fe8ee922277ff2735a03333119b21dc97934f04e7bc7832781cca9c29" }, "downloads": -1, "filename": "django-modeler-0.4.tar.gz", "has_sig": false, "md5_digest": "b9d95ec85f39d3a95b7bad0a347e12fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11437, "upload_time": "2011-09-09T19:27:45", "url": "https://files.pythonhosted.org/packages/de/65/07b3d44f30b342a85d7b7b05b715b0cba66a411579ee4d87e117ee90572e/django-modeler-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "560db886b4e4f5d5070c417ebe17de89", "sha256": "6719b01e004343f33f31275d6d6fc5cf8863b53fc42eee12967a611199a2d28e" }, "downloads": -1, "filename": "django-modeler-0.5.tar.gz", "has_sig": false, "md5_digest": "560db886b4e4f5d5070c417ebe17de89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7730, "upload_time": "2012-02-27T20:16:30", "url": "https://files.pythonhosted.org/packages/aa/86/fbc471b24ec458c02274c9527ee75c8684fcf71fd974611a9a610c29fa77/django-modeler-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "560db886b4e4f5d5070c417ebe17de89", "sha256": "6719b01e004343f33f31275d6d6fc5cf8863b53fc42eee12967a611199a2d28e" }, "downloads": -1, "filename": "django-modeler-0.5.tar.gz", "has_sig": false, "md5_digest": "560db886b4e4f5d5070c417ebe17de89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7730, "upload_time": "2012-02-27T20:16:30", "url": "https://files.pythonhosted.org/packages/aa/86/fbc471b24ec458c02274c9527ee75c8684fcf71fd974611a9a610c29fa77/django-modeler-0.5.tar.gz" } ] }