Skip to content

Commit

Permalink
docs correction Group model to ContactGroup model
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Dec 2, 2014
1 parent dcde77e commit 4defdcb
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 65 deletions.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/i18n.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/quickcharts.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/quickhowto.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/versions.doctree
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/_build/html/_sources/i18n.txt
Expand Up @@ -54,8 +54,8 @@ Let's work with the contacts application example, so you want to add translation
from flask.ext.babelpkg import lazy_gettext as _

class GroupModelView(ModelView):
datamodel = SQLAModel(Group, db.session)
related_views = [ContactModelView()]
datamodel = SQLAModel(ContactGroup)
related_views = [ContactModelView]

label_columns = {'name':_('Name')}

Expand Down
6 changes: 3 additions & 3 deletions docs/_build/html/_sources/quickcharts.txt
Expand Up @@ -233,11 +233,11 @@ by the framework of the columns them selfs.
::

class ContactChartView(ChartView):
search_columns = ['name','group']
search_columns = ['name','contact_group']
datamodel = SQLAModel(Contact)
chart_title = 'Grouped contacts'
label_columns = ContactModelView.label_columns
group_by_columns = ['group']
group_by_columns = ['contact_group']

Notice that:

Expand All @@ -256,7 +256,7 @@ Let's define a chart grouped by a time frame?
::

class ContactTimeChartView(TimeChartView):
search_columns = ['name','group']
search_columns = ['name','contact_group']
chart_title = 'Grouped Birth contacts'
label_columns = ContactModelView.label_columns
group_by_columns = ['birthday']
Expand Down
31 changes: 16 additions & 15 deletions docs/_build/html/_sources/quickhowto.txt
Expand Up @@ -37,7 +37,7 @@ you should be familiar with it's declarative syntax to define your database mode

On our example application we are going to define two tables,
a *Contact's* table that will hold the contacts detailed information,
and a *Group* table to group our contacts or classify them.
and a *ContactGroup* table to group our contacts or classify them.
We could additionally define a *Gender* table, to serve the role of enumerated values for 'Male' and 'Female'.

Although your not obliged to, i advise you to inherit your model classes from **Model** class.
Expand All @@ -49,20 +49,20 @@ and using it will allow you to define relations to User's.
You can add automatic *Audit* triggered columns to your models,
by inherit them from *AuditMixin* also. (see :doc:`api`)

So, first we are going to create a *Group* table, to group our contacts
So, first we are going to create a *ContactGroup* model, to group our contacts

Define your models (models.py)
------------------------------

The *Group* table.
The *ContactGroup* model.

::

from sqlalchemy import Column, Integer, String, ForeignKey, Date
from sqlalchemy.orm import relationship
from flask.ext.appbuilder import Model

class Group(Model):
class ContactGroup(Model):
id = Column(Integer, primary_key=True)
name = Column(String(50), unique = True, nullable=False)

Expand All @@ -80,24 +80,24 @@ The *Contacts* table.
birthday = Column(Date)
personal_phone = Column(String(20))
personal_celphone = Column(String(20))
group_id = Column(Integer, ForeignKey('group.id'))
group = relationship("Group")
contact_group_id = Column(Integer, ForeignKey('contact_group.id'))
contact_group = relationship("ContactGroup")

def __repr__(self):
return self.name


Notice that SqlAlchemy properties used here like 'unique', 'nullable' and 'default', will have special
treatment. In this case when adding a new *Contact* a query will be made to validate
if a someone with the same name already exists. Empty name contacts will not be allowed. Column types
if someone with the same name already exists. Empty name contacts will not be allowed. Column types
are validated. The address field will contain 'Street' has default on add form.
You can add your own custom validations also, take a look at :doc:`advanced`


Define your Views (views.py)
----------------------------

Now we are going to define our view for *Group* table.
Now we are going to define our view for *ContactGroup* model.
This view will setup functionality for create, remove, update and show primitives for your model's definition.

Inherit from *ModelView* class that inherits from *BaseCRUDView* that inherits from *BaseModelView*,
Expand All @@ -107,7 +107,7 @@ take a look at :doc:`advanced`.
::

class GroupModelView(ModelView):
datamodel = SQLAModel(Group)
datamodel = SQLAModel(ContactGroup)
related_views = [ContactModelView]


Expand All @@ -131,17 +131,18 @@ Let's define it::
class ContactModelView(ModelView):
datamodel = SQLAModel(Contact)

label_columns = {'group':'Contacts Group'}
list_columns = ['name','personal_celphone','birthday','group']
label_columns = {'contact_group':'Contacts Group'}
list_columns = ['name','personal_celphone','birthday','contact_group']

show_fieldsets = [
('Summary',{'fields':['name','address','group']}),
('Summary',{'fields':['name','address','contact_group']}),
('Personal Info',{'fields':['birthday','personal_phone','personal_celphone'],'expanded':False}),
]

Some explanation:

:label_columns: defines the labels for your columns. The framework will define the missing ones for you, with a pretty version of your column names.
:label_columns: defines the labels for your columns.
The framework will define the missing ones for you, with a pretty version of your column names.
:show_fieldsets: A fieldset (Django style). You can use show_fieldsets, add_fieldsets, edit_fieldsets
customize the show, add and edit views independently.

Expand All @@ -157,9 +158,9 @@ Remember you can include columns, relations or methods from a model's definition
.. note::

Fields that reference relationships display the defined related model representation
(on this case __repr__() methos on Group Model), so by default these fields can't be ordered.
(on this case __repr__() methos on ContactGroup Model), so by default these fields can't be ordered.
To enable order by on list for relationship fields, you can (since 1.1.1) reference
them using dotted notation. On this example would be 'group.name'.
them using dotted notation. On this example would be 'contact_group.name'.



Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/_sources/versions.txt
Expand Up @@ -8,7 +8,7 @@ Improvements and Bug fixes on 1.1.1
- New, get_order_columns_list receives optional list_columns to narrow search and auto include dotted cols.
- New, dotted columns are also automatically pretty labeled.
- Fix, is<Type col> on SQLInterface handles exceptions for none existing cols.
- Fix, back special URL included on a new View called UtilView, removes bug when replacing IndexView the back crashes.
- Fix, back special URL included on a new View called UtilView, removes bug: when replacing IndexView the back crashes.

Improvements and Bug fixes on 1.1.0
-----------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/i18n.html
Expand Up @@ -111,8 +111,8 @@ <h2>Quick How to<a class="headerlink" href="#quick-how-to" title="Permalink to t
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">flask.ext.babelpkg</span> <span class="kn">import</span> <span class="n">lazy_gettext</span> <span class="k">as</span> <span class="n">_</span>

<span class="k">class</span> <span class="nc">GroupModelView</span><span class="p">(</span><span class="n">ModelView</span><span class="p">):</span>
<span class="n">datamodel</span> <span class="o">=</span> <span class="n">SQLAModel</span><span class="p">(</span><span class="n">Group</span><span class="p">,</span> <span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="p">)</span>
<span class="n">related_views</span> <span class="o">=</span> <span class="p">[</span><span class="n">ContactModelView</span><span class="p">()]</span>
<span class="n">datamodel</span> <span class="o">=</span> <span class="n">SQLAModel</span><span class="p">(</span><span class="n">ContactGroup</span><span class="p">)</span>
<span class="n">related_views</span> <span class="o">=</span> <span class="p">[</span><span class="n">ContactModelView</span><span class="p">]</span>

<span class="n">label_columns</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span><span class="n">_</span><span class="p">(</span><span class="s">&#39;Name&#39;</span><span class="p">)}</span>

Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/py-modindex.html
Expand Up @@ -89,7 +89,7 @@ <h1>Python Module Index</h1>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="views.html#module-flask.ext.appbuilder.baseviews"><tt class="xref">flask.ext.appbuilder.baseviews</tt></a></td><td>
<a href="quickhowto.html#module-flask.ext.appbuilder.baseviews"><tt class="xref">flask.ext.appbuilder.baseviews</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
Expand Down
6 changes: 3 additions & 3 deletions docs/_build/html/quickcharts.html
Expand Up @@ -308,11 +308,11 @@ <h2>Grouped Data Charts<a class="headerlink" href="#grouped-data-charts" title="
<div class="section" id="deprecated-define-your-chart-views-views-py">
<h2>(Deprecated) Define your Chart Views (views.py)<a class="headerlink" href="#deprecated-define-your-chart-views-views-py" title="Permalink to this headline"></a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ContactChartView</span><span class="p">(</span><span class="n">ChartView</span><span class="p">):</span>
<span class="n">search_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">,</span><span class="s">&#39;group&#39;</span><span class="p">]</span>
<span class="n">search_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">,</span><span class="s">&#39;contact_group&#39;</span><span class="p">]</span>
<span class="n">datamodel</span> <span class="o">=</span> <span class="n">SQLAModel</span><span class="p">(</span><span class="n">Contact</span><span class="p">)</span>
<span class="n">chart_title</span> <span class="o">=</span> <span class="s">&#39;Grouped contacts&#39;</span>
<span class="n">label_columns</span> <span class="o">=</span> <span class="n">ContactModelView</span><span class="o">.</span><span class="n">label_columns</span>
<span class="n">group_by_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;group&#39;</span><span class="p">]</span>
<span class="n">group_by_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;contact_group&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>Notice that:</p>
Expand All @@ -335,7 +335,7 @@ <h2>(Deprecated) Define your Chart Views (views.py)<a class="headerlink" href="#
<p>You can use &#8216;BarChart&#8217;, &#8216;LineChart&#8217;, &#8216;AreaChart&#8217; the default is &#8216;PieChart&#8217;, take a look at the google charts documentation, the <em>chart_type</em> is the function on &#8216;google.visualization&#8217; object</p>
<p>Let&#8217;s define a chart grouped by a time frame?</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ContactTimeChartView</span><span class="p">(</span><span class="n">TimeChartView</span><span class="p">):</span>
<span class="n">search_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">,</span><span class="s">&#39;group&#39;</span><span class="p">]</span>
<span class="n">search_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">,</span><span class="s">&#39;contact_group&#39;</span><span class="p">]</span>
<span class="n">chart_title</span> <span class="o">=</span> <span class="s">&#39;Grouped Birth contacts&#39;</span>
<span class="n">label_columns</span> <span class="o">=</span> <span class="n">ContactModelView</span><span class="o">.</span><span class="n">label_columns</span>
<span class="n">group_by_columns</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;birthday&#39;</span><span class="p">]</span>
Expand Down

0 comments on commit 4defdcb

Please sign in to comment.