don't display primary-key field in edit view starlette-admin

111 views Asked by At

Need help. I connect starlette-admin in my project. But if i try to edit Primary key column, I can't see this field in admin-view. enter image description here

from starlette.applications import Starlette
from starlette_admin.contrib.sqla import Admin, ModelView

from database import Base
from database import engine

# импортируем модели
from models import ClientsTable, TelegramClientTable, TeletonBotsTable
from models import CustomersTable, ChatGptConfigTable, ChatGptRequestsTable
from models import ChatGptResponceTable


class TeletoneBotsTableView(ModelView):
    fields = ["id", "customer", "created_at"]


Base.metadata.create_all(engine)

# Создаем приложение FastAPI()
app = Starlette()

admin = Admin(engine, title="BotSeller")

admin.add_view(ModelView(ClientsTable))
admin.add_view(ModelView(TelegramClientTable))

admin.add_view(TeletoneBotsTableView(TeletonBotsTable))

admin.add_view(ModelView(CustomersTable))
admin.add_view(ModelView(ChatGptConfigTable))
admin.add_view(ModelView(ChatGptRequestsTable))
admin.add_view(ModelView(ChatGptResponceTable))

admin.mount_to(app)

I try to change ModelView Configurations, but it not work.

1

There are 1 answers

0
jowilf On

You need to set the form_include_pk parameter to True.

Example:

class TeletoneBotsTableView(ModelView):
    fields = ["id", "customer", "created_at"]
    form_include_pk = True

For more detail, checkout this example -> https://github.com/jowilf/starlette-admin/blob/8070ae0b46071b75e88bbde6605ecfc6cfef9fd7/examples/sqla/views.py#L61