Commit 79f4f907 authored by Serge S. Koval's avatar Serge S. Koval

Wording

parent fc910bb9
...@@ -106,10 +106,11 @@ configuration properties and methods. ...@@ -106,10 +106,11 @@ configuration properties and methods.
Multiple Primary Keys Multiple Primary Keys
--------------------- ---------------------
Models with multiple primary keys have limited support, as a few pitfalls are waiting for you. Flask-Admin has limited support for models with multiple primary keys. It only covers specific case when
With using multiple primary keys, weak entities can be used with Flask-Admin. all but one primary keys are foreign keys to another model. For example, model inheritance following
this convention.
Lets Model a car with it's tyres:: Lets Model a car with its tyres::
class Car(db.Model): class Car(db.Model):
__tablename__ = 'cars' __tablename__ = 'cars'
...@@ -129,19 +130,17 @@ Lets Model a car with it's tyres:: ...@@ -129,19 +130,17 @@ Lets Model a car with it's tyres::
A specific tyre is identified by using the two primary key columns of the ``Tyre`` class, of which the ``car_id`` key A specific tyre is identified by using the two primary key columns of the ``Tyre`` class, of which the ``car_id`` key
is itself a foreign key to the class ``Car``. is itself a foreign key to the class ``Car``.
To be able to CRUD the ``Tyre`` class, two steps are necessary, when definig the AdminView:: To be able to CRUD the ``Tyre`` class, you need to enumerate columns when defining the AdminView::
class TyreAdmin(sqla.ModelView): class TyreAdmin(sqla.ModelView):
form_columns = ['car', 'tyre_id', 'desc'] form_columns = ['car', 'tyre_id', 'desc']
The ``form_columns`` needs to be explizit, as per default only one primary key is displayed. When, like in this The ``form_columns`` needs to be explicit, as per default only one primary key is displayed.
example, one part of the key is a foreign key, do not include the foreign-key-columns here, but the
corresponding relationship.
When having multiple primary keys, **no** validation for uniqueness *prior* to saving of the object will be done. Saving When having multiple primary keys, **no** validation for uniqueness *prior* to saving of the object will be done. Saving
a model that violates a unique-constraint leads to an Sqlalchemy-Integrity-Error. In this case, ``Flask-Admin`` displays a model that violates a unique-constraint leads to an Sqlalchemy-Integrity-Error. In this case, ``Flask-Admin`` displays
a proper error message and you can change the data in the form. When the application has been started with ``debug=True`` a proper error message and you can change the data in the form. When the application has been started with ``debug=True``
the ``werkzeug`` debugger catches the exception and displays the stacktrace. the ``werkzeug`` debugger will catch the exception and will display the stacktrace.
A standalone script with the Examples from above can be found in the examples directory. A standalone script with the Examples from above can be found in the examples directory.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment