askrobots / dbbasic-examples
Public
Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.
danq9
Add official module template for creating DBBasic packages
17cf88a
1 year, 1 month ago
History
QUICKSTART.md · 2.4 KB · 127 lines
Quick Start: Create a DBBasic Module in 5 Minutes
1. Copy Template
cp -r module-template dbbasic-contacts
cd dbbasic-contacts
2. Rename Package
# Rename directory
mv dbbasic_module dbbasic_contacts
# Replace "module" with "contacts" in all files
find . -type f -exec sed -i '' 's/dbbasic-module/dbbasic-contacts/g' {} +
find . -type f -exec sed -i '' 's/dbbasic_module/dbbasic_contacts/g' {} +
find . -type f -exec sed -i '' 's/Module/Contacts/g' {} +
# On Linux use: sed -i (without the '')
3. Update Metadata
Edit pyproject.toml:
name = "dbbasic-contacts"
description = "Contact management for DBBasic"
author = "Your Name"
email = "you@example.com"
Edit dbbasic_contacts/admin.py:
ADMIN_CONFIG = [{
'icon': '👤',
'label': 'Contacts',
'href': '/admin/contacts',
'order': 40
}]
4. Define Fields
Edit dbbasic_contacts/contacts.py, update the schema:
self.schema = {
'id': int,
'name': str,
'email': str,
'phone': str,
'company': str,
'created_at': str,
}
5. Install & Test
pip install -e .
python manage.py serve
open http://localhost:8000/admin/contacts
Done! You now have a working module with admin interface.
What You Get
- ✅ List view at
/admin/contacts - ✅ Create form at
/admin/contacts/create - ✅ Edit form at
/admin/contacts/edit/[id] - ✅ Delete at
/admin/contacts/delete/[id] - ✅ Python API:
Contacts().create(),.list(),.get(),.update(),.delete() - ✅ Automatic menu integration
- ✅ TSV-based storage
Customize
Add More Fields
Edit dbbasic_contacts/contacts.py:
# Add to schema
self.schema = {
# ... existing fields ...
'birthday': str,
'notes': str,
}
# Add validation in create()
if 'email' not in kwargs:
raise ValueError("Email required")
Customize List View
Edit dbbasic_contacts/api/contacts/list.py:
- Change columns in table
- Add search/filter
- Customize styling
Add Custom Methods
Edit dbbasic_contacts/contacts.py:
def search_by_company(self, company):
return self.search(company=company)
def get_by_email(self, email):
results = self.search(email=email)
return results[0] if results else None
Publish
python -m build
python -m twine upload dist/*
Now anyone can:
pip install dbbasic-contacts
And they get your module + admin interface automatically!