Skip to content

Commit 928e4b8

Browse files
author
Mark Gibbs
committed
Add documentation and bump version number to 0.3.0
1 parent 921df5b commit 928e4b8

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

django_plotly_dash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22

3-
__version__ = "0.2.2"
3+
__version__ = "0.3.0"
44

55
from .dash_wrapper import DjangoDash
66

django_plotly_dash/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def save(self, *args, **kwargs):
2626
return super(StatelessApp, self).save(*args,**kwargs)
2727

2828
def as_dash_app(self):
29+
'''
30+
Return a DjangoDash instance of the dash application
31+
'''
2932
dd = getattr(self,'_stateless_dash_app_instance',None)
3033
if not dd:
3134
dd = get_stateless_by_name(self.app_name)

docs/models_and_state.rst

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
11
.. _models_and_state:
22

33
Django models and application state
4-
================
4+
===================================
55

6-
The ``django_plotly_dash`` application defines a ``DashApp`` model. This represents an instance of application state.
6+
The ``django_plotly_dash`` application defines ``DashApp`` and ``StatelessApp`` models.
7+
8+
The ``StatelessApp`` model
9+
----------------------
10+
11+
An instance of the ``StatelessApp`` model represents a single dash application. Every instantiation of
12+
a ``DjangoDash`` object is registered, and any object that is referenced through the ``DashApp`` model - this
13+
includes all template access as well as model instances themselves - causes a ``StatelessApp`` model instance to
14+
be created if one does not already exist.
15+
16+
.. code-block:: python
17+
18+
class StatelessApp(models.Model):
19+
'''
20+
A stateless Dash app.
21+
22+
An instance of this model represents a dash app without any specific state
23+
'''
24+
25+
app_name = models.CharField(max_length=100, blank=False, null=False, unique=True)
26+
slug = models.SlugField(max_length=110, unique=True, blank=True)
27+
28+
def as_dash_app(self):
29+
'''
30+
Return a DjangoDash instance of the dash application
31+
'''
32+
33+
The main role of a ``StatelessApp`` instance is to manage access to the associated ``DjangoDash`` object, as
34+
expsosed through the ``as_dash_app`` member
35+
function.
36+
37+
The ``DashApp`` model
38+
---------------------
39+
40+
An instance of the ``DashApp`` model represents an instance of application state.
741

842
.. code-block:: python
943
1044
class DashApp(models.Model):
1145
'''
1246
An instance of this model represents a Dash application and its internal state
1347
'''
14-
app_name = models.CharField(max_length=100, blank=False, null=False, unique=False)
48+
stateless_app = models.ForeignKey(StatelessApp, on_delete=models.PROTECT,
49+
unique=False, null=False, blank=False)
1550
instance_name = models.CharField(max_length=100, unique=True, blank=True, null=False)
1651
slug = models.SlugField(max_length=110, unique=True, blank=True)
1752
base_state = models.TextField(null=False, default="{}")
@@ -36,7 +71,7 @@ The ``django_plotly_dash`` application defines a ``DashApp`` model. This represe
3671
Add values from the underlying dash layout configuration
3772
'''
3873
39-
The ``app_name`` corresponds to an application registered through the instantiation of a ``DjangoDash`` object. The ``slug`` field provides a unique identifier
74+
The ``stateless_app`` references an instance of the ``StatelessApp`` model described above. The ``slug`` field provides a unique identifier
4075
that is used in URLs to identify the instance of an application, and also its associated server-side state.
4176
4277
The persisted state of the instance is contained, serialised as JSON, in the ``base_state`` variable. This is an arbitrary subset of the internal state of the

docs/template_tags.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ a ``DjangoDash`` app within a page as a responsive ``iframe`` element.
1515
The tag arguments are:
1616

1717
:name = None: The name of the application, as passed to a ``DjangoDash`` constructor.
18-
:slug = None: The slug of the application instance.
18+
:slug = None: The slug of an existing ``DashApp`` instance.
1919
:da = None: An existing ``django_plotly_dash.models.DashApp`` model instance.
2020
:ratio = 0.1: The ratio of height to width. The container will inherit its width as 100% of its parent, and then rely on
2121
this ratio to set its height.
@@ -24,4 +24,3 @@ The tag arguments are:
2424
At least one of ``da``, ``slug`` or ``name`` must be provided. An object identified by ``slug`` will always be used, otherwise any
2525
identified by ``name`` will be. If either of these arguments are provided, they must resolve to valid objects even if
2626
not used. If neither are provided, then the model instance in ``da`` will be used.
27-

0 commit comments

Comments
 (0)