The aim of this project is to provide an StarUML extension to:
- Auto-generate Python PeeWee Model Classes from an Entity Relationship Diagram (ERD).
- Install StarUML, download page.
- Download or clone this repo.
- Copy repo files to StarUML extension user folder:
- MacOS:
~/Library/Application Support/StarUML/extensions/user/staruml-peewee - Windows:
C:\Users\<user>\AppData\Roaming\StarUML\extensions\user\staruml-peewee - Linux:
~/.config/StarUML/extensions/user/staruml-peewee
First create a ERD defining the database layout in StarUML. Then run this extension to translate that to a Python PeeWee Model corresponding to the same database schema which you have defined. Specifically,
- Click the menu (
Tools > PeeWee Database Model > Generate Code...) - If necessary, select a base model (or package) that will be generated to PeeWee database model.
- Select a folder where the generated Python source file (.py) will be placed.
#===============================================================================
# PeeWee Database Model
#===============================================================================
from peewee import *
db = SqliteDatabase('data.db')
#-------------------------------------------------------------------------------
class BaseModel(Model):
class Meta:
database = db
#-------------------------------------------------------------------------------
class Good(BaseModel):
"""A good is something which you can make or buy"""
name = CharField(unique = True)
baseValue = IntegerField()
class Recipe(BaseModel):
name = CharField(max_length = 80)
amountProduced = IntegerField()
product = ForeignKeyField(Good)
class Ingredients(BaseModel):
amount = IntegerField()
good = ForeignKeyField(Good)
recipe = ForeignKeyField(Recipe, backref = "ingredients")This project is provided as-is, with no implied warranty of any kind. This is very much a work-in-progress. Feel free to report any bugs that you find here via github.
- Charles Hill nopaniers@gmail.com
This project is based on a similar project, staruml-django, by josemlp91.
If you find this useful, feel free to buy me a coffee.