0
@@ -86,6 +86,65 @@ These steps are all you need to do to have new Midgard objects at your disposal.
0
+### And the same in Python
0
+Since Midgard is a multilingual framework, same content can be accessed between PHP, Python and C APIs. Here is the Python version of the PHP example above:
0
+ # -*- coding: utf-8 -*-
0
+ import _midgard as midgard
0
+ config = midgard.config()
0
+ # read default configuration
0
+ opened = config.read_file('midgard', True)
0
+ raise SystemError("Failed to open default configuration file")
0
+ cnc = midgard.connection()
0
+ connected = cnc.open_config(config)
0
+ reporter = midgard.mgdschema.midgard_person()
0
+ reporter.set_property("firstname", "John")
0
+ reporter.set_property("lastname", "Smith")
0
+ # Save it to the database
0
+ reporter_guid = reporter.get_property("guid")
0
+ # And it can be fetched from the database
0
+ qb = midgard.query_builder("midgard_person")
0
+ # We have multiple ways to query objects
0
+ qb.add_constraint("lastname", "LIKE", "Smi%")
0
+ article = midgard.mgdschema.midgard_article()
0
+ article.set_property("title", "MidCOM is cool")
0
+ metadata = article.get_property("metadata")
0
+ metadata.set_property("authors", reporter_guid)
0
+ # Extend the article with new properties
0
+ article.set_parameter("namespace", "key", "value")
0
+ # Localize the article to Finnish
0
+ article.set_property("title", "MidCOM on Šltsin magee")
0
+ # Delete the Finnish translation
0
## A dynamic admin interface
0
Midgard comes with [Asgard][18], an automated administrative interface which provides a full editing tool to all our installed MgdSchemas. If your define a tree model for your storage, it will even provide a nice navigation tree for them. For example:
Comments
No one has commented yet.