11.. _PiccoloApps :
22
3+ ############
34Piccolo Apps
4- ============
5+ ############
56
67By leveraging Piccolo apps you can:
78
8- * Modularise your code.
9- * Share your apps with other Piccolo users.
10- * Unlock some useful functionality like auto migrations.
9+ * Modularise your code.
10+ * Share your apps with other Piccolo users.
11+ * Unlock some useful functionality like auto migrations.
1112
13+ -------------------------------------------------------------------------------
14+
15+ ***************
1216Creating an app
13- ---------------
17+ ***************
1418
1519Run the following command within your project:
1620
@@ -19,7 +23,7 @@ Run the following command within your project:
1923 piccolo app new my_app
2024
2125
22- This will create a folder like this:
26+ Where ` my_app ` is your new app's name. This will create a folder like this:
2327
2428.. code-block :: bash
2529
@@ -43,8 +47,11 @@ It's important to register your new app with the ``APP_REGISTRY`` in
4347 Anytime you invoke the `piccolo ` command, you will now be able to perform
4448operations on your app, such as :ref: `Migrations `.
4549
50+ -------------------------------------------------------------------------------
51+
52+ *********
4653AppConfig
47- ---------
54+ *********
4855
4956Inside your app's `piccolo_app.py ` file is an ``AppConfig `` instance. This is
5057how you customise your app's settings.
@@ -75,7 +82,7 @@ how you customise your app's settings.
7582 )
7683
7784 app_name
78- ~~~~~~~~
85+ ========
7986
8087This is used to identify your app, when using the `piccolo ` CLI, for example:
8188
@@ -84,24 +91,55 @@ This is used to identify your app, when using the `piccolo` CLI, for example:
8491 piccolo migrations forwards blog
8592
8693 migrations_folder_path
87- ~~~~~~~~~~~~~~~~~~~~~~
94+ ======================
8895
8996Specifies where your app's migrations are stored. By default, a folder called
9097`piccolo_migrations ` is used.
9198
9299table_classes
93- ~~~~~~~~~~~~~
100+ =============
101+
102+ Use this to register your app's ``Table `` subclasses. This is important for
103+ auto migrations (see :ref: `Migrations `).
104+
105+ You can register them manually, see the example above, or can use
106+ ``table_finder ``.
107+
108+ table_finder
109+ ------------
110+
111+ Instead of manually registering ``Table `` subclasses, you can use
112+ ``table_finder `` to automatically import any ``Table `` subclasses from a given
113+ list of modules.
114+
115+ .. code-block :: python
116+
117+ from piccolo.conf.apps import table_finder
118+
119+ APP_CONFIG = AppConfig(
120+ app_name = ' blog' ,
121+ migrations_folder_path = os.path.join(CURRENT_DIRECTORY , ' piccolo_migrations' ),
122+ table_classes = table_finder(modules = [' blog.tables' ]),
123+ migration_dependencies = [],
124+ commands = []
125+ )
126+
127+ The module path should be from the root of the project (the same directory as
128+ your ``piccolo_conf.py `` file, rather than a relative path).
129+
130+ .. currentmodule :: piccolo.conf.apps
131+
132+ .. autofunction :: table_finder
94133
95- Use this to register your app's tables. This is important for auto migrations (see :ref: `Migrations `).
96134
97135migration_dependencies
98- ~~~~~~~~~~~~~~~~~~~~~~
136+ ======================
99137
100138Used to specify other Piccolo apps whose migrations need to be run before the
101139current app's migrations.
102140
103141commands
104- ~~~~~~~~
142+ ========
105143
106144You can register functions and coroutines, which are automatically added to
107145the `piccolo ` CLI.
@@ -155,8 +193,11 @@ app.
155193 Piccolo itself is bundled with several apps - have a look at the source code
156194for inspiration.
157195
196+ -------------------------------------------------------------------------------
197+
198+ ************
158199Sharing Apps
159- ------------
200+ ************
160201
161202By breaking up your project into apps, the project becomes more maintainable.
162203You can also share these apps between projects, and they can even be installed
0 commit comments