{"id":16411453,"url":"https://github.com/yetone/activemodel","last_synced_at":"2025-11-16T02:07:24.476Z","repository":{"id":32178852,"uuid":"35752259","full_name":"yetone/activemodel","owner":"yetone","description":"Automatically exported from code.google.com/p/activemodel","archived":false,"fork":false,"pushed_at":"2015-05-17T04:46:10.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T07:49:59.097Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yetone.png","metadata":{"files":{"readme":"readme.txt","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-17T04:42:38.000Z","updated_at":"2015-05-17T04:44:18.000Z","dependencies_parsed_at":"2022-09-11T04:41:09.390Z","dependency_job_id":null,"html_url":"https://github.com/yetone/activemodel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Factivemodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Factivemodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Factivemodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yetone%2Factivemodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yetone","download_url":"https://codeload.github.com/yetone/activemodel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240416782,"owners_count":19797880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T06:45:32.829Z","updated_at":"2025-11-16T02:07:24.432Z","avatar_url":"https://github.com/yetone.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#summary README\n\nactivemodel - an !ActiveRecord implementation as seen in Rails for Python\nby Henning Schroeder (henning.schroeder@gmail.com)\n\n= Description =\n\nEvery model class represents a table in the database. Instances of the class\nrepresent rows of the table and the attributes of an instance are the\ncolumn values of the row.\n\nUnlike other object relationional mappers (ORMs) you do not have to\nspecify the columns in the class. This follows the Don't-Repeat-Yourself\nprinciple ([http://en.wikipedia.org/wiki/DRY_code DRY]). \n\n== Warning ==\n\nThis software is more or less a proof of concept and far from complete. It is neither\nfully tested nor working without errors. \n\nIf you need a Python ORM _now_, please look at [http://www.sqlalchemy.org SQLAlchemy] \nor [http://www.sqlobject.org SQLObject].\n\n\n= How to use =\n\nFirst you have to import the package\n{{{\n \u003e\u003e\u003e from activemodel import *\n}}}\nThen you define a class which is already in the database\n{{{\n \u003e\u003e\u003e class Post(Model): pass\n}}}\nThat's it! You now can access your table.\n{{{\n \u003e\u003e\u003e first_post = Post.find(1)\n \u003e\u003e\u003e print first_post.subject\n The ist my first post\n \u003e\u003e\u003e new_post = Post.create(subject=\"New\", body=\"blala\")\n}}}\nIf a column has the same name as a used method or class attribute or\nis no valid Python attribute you can also access it as a dictionary item.\n{{{\n \u003e\u003e\u003e s = first_post[\"subject\"]\n}}}\n\n\n== Model class ==\n\nThe class has the following attributes\n\n * table_name\n   Normallly you write class names in singular !CamelCase. By\n   convention tables are lower case and plural. So the name gets \n   translated to camel_cases. \n   If your table has another name you can set it here. \n   {{{\n     \u003e\u003e\u003e class DataModel(Model):\n     ...    table_name = \"Model\"\n   }}}\n   As you see it can be helpful if your table is a reserved word \n   in Python or you have a legacy table.\n * pluralize_table_names (default is True)\n   If you don't like plural names, you can disable it. \n   {{{\n     \u003e\u003e\u003e class Data(Model):\n     ....   pluralize_table_names = False\n   }}}\n   When True the function activemodel.utils.pluralize tries to pluralize\n   the name according to English plural rules. See\n   [http://en.wikipedia.org/wiki/English_plural the wikipedia article]\n   for more information.\n   You can also set it globally with\n   {{{\n     \u003e\u003e\u003e Model.pluralize_table_names = False\n   }}}\n * convert_camelcase (default is True)\n * table_columns\n   This is a dictionary with the column name and column object.  \n * primary_key (default is \"id\")\n   If your primary key is something else you can specify it here.\n * auto_save (default is False)\n   When True the save method is called after every attribute change.\n   \n   \nTo open a database connection use the following class method\n * establish_connection\n   {{{\n   \u003e\u003e\u003e Model.establish_connection(\"mysql://root@localhost/databasename\")\n   }}}\n   You can also use keyword paramaters instead of a database url\n   {{{\n   \u003e\u003e\u003e Model.establisj_connection(adapter=\"mysql\", database=\"test\")\n   }}}\n\n\nSome magic\n  * When a table has an attribute called created_on or created_at, it\n    will be automatically set on create.\n  * The attributes updated_on and updated_at are similar. They are\n    automatically set on update.\n  \n \n=== Behaviours ===\n\n*These will be explained when they are fully implemented*\n\n * has_many\n * belongs_to\n * has_one\n * has_and_belongs_to_many\n * serialize - see activemodel/extensions/serialize.py for documentation\n\n\n=== Class Methods ===\n * create\n   {{{\n     \u003e\u003e\u003e first_post = Post.create(subject=\"first post!\", body=\"bla bla\")\n   }}}\n   This is the same as\n   {{{\n     \u003e\u003e\u003e first_post = Post(subject=\"first post!\", body=\"bla bla\")\n     \u003e\u003e\u003e first_post.save()\n   }}}\n * delete-methods\n   {{{ \n     \u003e\u003e\u003e Post.delete(1)     # delete row with primary key = 1\n     \u003e\u003e\u003e Post.delete([1,3]) # delete row with primary key = 1 or 3\n     \u003e\u003e\u003e Post.delete_by_subject(\"first post!\")\n     \u003e\u003e\u003e Post.delete_by_subject_and_body(\n     ...      [\"first_post!\", \"another subject\"], \"bla bla\")\n   }}}\n   The by-methods will be dynamically generated and can contain one\n   or more column_names. \n * find-methods\n   Like the delete-methods there are several ways to search.\n   When find(primarykey) does not find a row it will raise the\n   ModelNotFound exception.\n   {{{\n     \u003e\u003e\u003e p = Post.find(1)\n     \u003e\u003e\u003e p = Post.find_by_subject(\"first post!\")\n     \u003e\u003e\u003e p = Post.find_by_subject([\"first post!\", \"another subject\"])\n     \u003e\u003e\u003e plist = Post.find_all_by_subject(\"spam\")\n     \u003e\u003e\u003e plist = Post.find_all_by_subject_and_body(\"foo\", \"bar\")\n     \u003e\u003e\u003e p = Post.find_by(subject_ne=\"spam\")\n     \u003e\u003e\u003e plist = Post.find_all_by(id_gt=1)\n   }}}\n * find_or_create_by\n   Instead of raising an error a new object will be created and saved.\n   {{{\n     \u003e\u003e\u003e p = Post.find_or_create_by_subject(\"hello, world!\",\n     ...        create_data={\"body\": \"bye\"})\n   }}}\n   The keyword parameter create_data is optional and is used when no\n   object was found to create a new one together with the search data.\n   p.__created__ is True if the object was created.\n * update\n\n\n=== Instance Methods ===\n * delete\n   {{{\n     \u003e\u003e\u003e Post.delete(1)\n     \u003e\u003e\u003e Post.delete_by_subject(\"first post!\")  \n   }}}\n * save\n * update\n * to_xml - see activemodel/extensions/toxml.py for documentation\n\n\n== Query class ==\n * The functions select and where help to use query objects.\n   {{{\n     \u003e\u003e\u003e query = select(\n     ...     Post.subject, Comment.id.count().as(\"comment_count\")\n     ...   ).where(\n     ...      Post.id == Comment.posts_id\n     ...\t ).order_by(\"comment_count\").group_by(Post.id)\n     \u003e\u003e\u003e for row in query:\n     ...    print \"%r has %s comments\" % (row[\"subject\"], row[\"comment_count\"]) \n   }}}\n \n\n== Extending ==\n * examples from serialize and toxml\n \n \n= TODO =\n * more database backends (sqlite, postgresql)\n * fix and complete code with # XXX:\n * tag_with/taggable\n * acts_as\n * validation\n * migration","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetone%2Factivemodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyetone%2Factivemodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyetone%2Factivemodel/lists"}