Sometimes it is easier to design and talk about models in a more abstract easy to change way. After that design phase is finished, it is nice to have something to take your designs and give you boilerplate code. This does that for Django when models are specified in a specific style in Trello. An example board https://trello.com/b/iPHi7eQz/my-django-models.
py-trello==0.1.6
is installedpy-trello
has a bug that is easily fixed, edit theenv/lib/python2.X/site-packages/trello/__init__.py
line 577. Change it fromself.due = json_obj.get('due', '')[:10]
toif json_obj.get('due', ''): self.due = json_obj.get('due', '')[:10]
- Environment variables are set;
TRELLO_KEY
,TRELLO_SECRET
,TRELLO_TOKEN
- Each list that starts with "Model:" will be turned into a Django model. All other syntax is based on the cards in those lists.
- All cards are created as attributes/fields in the Django model, unless they have a label 'ignored'.
- The name of the card is the name of the field in the model.
- For relationships the name of the card should be the field name followed by a '>' followed by the name of the model that is linked. Adding a 'link' label also is important. Ex.
author > Author
- Card descriptions should contain the Django model field name (CharField, TextField, etc).
- If you want to set other attributes on the Django field specify them in the description of the card as well after the field type followed by colon, and colon separated. Ex.
CharField:max_length=255:default='blah'
- The default field is
CharField(max_length=255)
. - For relationships, the description of the card works the same way, but the first property after the type should be the related_name of the relationship. Ex
ForeignKey:books
. Other properties can then be specified after that, colon separated. - If you want to specify choices for a field, create a checklist in trello for that card, call it 'choices' and specify the choices as checklist items.
- You can also use a label called 'optional', to specify optional fields. This will set
null=True
andblank=True
for fields with this label.