Navigation

There are a number of projects now that sport a Django ORM-like syntax, where
fields are declared at the class level and some kind of “meta” class exists.
Unlike other projects that attempt to hack the Django ORM, this one attempts to
encompass those as well. This project right now will let you declare ORM models
dynamically, including ones for GeoDjango, and it will allow you to declare
TastyPie APIs dynamically, including those that can output GeoJSON via
tastyhacks (ga_ows) is required for this functionality, as it includes
:mod:tastyhacks.py. Soon you should also be able to use MongoEngine models.

In the near future, you will also be able to expose these models via WFS and WMS using Geoanalytics OWS services.

To facilitate a “push-to-publish” model of data publishing, RENCI’s Geoanalytics introduces “dynamic models” to Django.
Dynamic models allow you to build forms and views that will allow a user to upload data in a controlled fashion. This
data will then populate a database table or series of tables in the ORM. Models will be generated and these models will
be automagically exposed to the Admin interface and can be added dynamically to RESTful APIs as well through Tastypie.

These are used by other apps as well, and effectively create a routing mechanism for connections that use the raw
pymongo driver. The values in MONGODB_ROUTES can change depending on your particular database configuration. If
ga_dynamic_models is listed as a route in the settings, then this app will use that route, otherwise it will use

the default route and create two new collections, ga_dynamic_models__models and ga_dynamic_models__apis.

This app is still very early in its development stage. Although it is working, parts of the application regarding
management are currently lacking. Currently there are no management views setup for this application. The dynamic
models and APIs themselves are not listed in the admin application. Furthermore there are no default forms setup for
creating dynamic models. There will be soon, but for now this application seems useful and generic enough to make
available.

Once you have fulfilled the main requirements, add ga_dynamic_models to your INSTALLED_APPS section in Django’s
settings, and add an entry for ga_dynamic_models.urls in your main urls.py. This will create an endpoint at
^/api/ga_dynamic_models that will build out as more dynamic models are added. See the django tastypie
documentation for more details on how Tastypie RESTful APIs work. They are largely compatible with popular client-side
libraries like jQuery, jQueryMobile, ExtJS4, and Sencha Touch.

The only way to create a model right now is in Python code. The module ga_dynamic_models.utils contains tools to
help you do this. The simplest way is to use the declare_model function and the simple_(geo)model function
like so:

The declare_model function adds a new model to the list. Note this does NOT create any tables in your main database.
To do that, you MUST run the syncdb task yourself, or achieve this in code. It does however, expose the model to
the Admin interface, if you have enabled the admin application.

The declare_resource function adds a model to the API. See the utils module for more details on how these functions
work and the Django model Meta options and Tastypie Meta options pages on what extra meta options can be passed
to these functions. More documentation will be forthcoming on this module, but for now you’re kind of going to be
stuck reading the code a bit. Check the tests.py file for examples of usage.