URL mapping

Introduction

CRUD provides translation of SQLAlchemy object ids to URL paths and vice versa.

The default behavior is to read uuid attribute and do base64 encoding for it:

from websauna.system.crud import Base64UUIDMapper

class CRUD(_Resource):
    mapper = Base64UUIDMapper(mapping_attribute="uuid")

You can change the name of the attribute. For example if your model has UUID based primary key id and doesn’t have a separate uuid attribute:

from websauna.system.admin.modeladmin import ModelAdmin, model_admin

from .models import UserOwnedAccount
from websauna.system.crud import Base64UUIDMapper

@model_admin(traverse_id="user-accounts")
class UserAccountAdmin(ModelAdmin):
    """Manage user owned accounts and their balances."""

    model = UserOwnedAccount
    mapper = Base64UUIDMapper(mapping_attribute="id")