aminalaee/sqladmin

JsonFiled in admin page does not show

atenagh opened this issue · 4 comments

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

Hi Amin
I have model with one json field. when I use JSONField that I imported from sqladmin, there is no error but in my admin panel for Notification instance variables json filed does not show.

here is my notification admin code.

from sqladmin import ModelView
from models import Notification

class NotificationAdmin(ModelView, model=Notification):
    column_list = [Notification.id]

here is my notification model code.

from sqladmin.fields import JSONField
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Notification(Base):
    __tablename__ = 'notifications'
    id = Column(Integer, primary_key=True)
    variables = JSONField()

instead when I use JSON that I imported from sqlalchemy with previous admin code, I got 500 internal error.
here is my notification model code.

from sqlalchemy import Column, JSON, Integer
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Notification(Base):
    __tablename__ = 'notifications'
    id = Column(Integer, primary_key=True)
    variables = Column(JSON)

Steps to reproduce the bug

create admin panel for notification model with attached code and create notification model

Expected behavior

for first issue I expect json field show in admin panel
in second issue I expect It work with sqlalchemy JSON.

Actual behavior

in first issue it doesn't show the json filed and in second issue I got 500 internall server error.

Debugging material

No response

Environment

windows 11
python 3.10
sqladmin 0.19.0

Additional context

No response

cant reproduce with JSON from sqlalchemy - looks correct:

image

Hi Amin
I really appreciate your response
can you show me your exact code included your User model with json field and imported that use for defining json filed and its appropriate admin code.

Thanks

its just simple example from tutorial with json field

from sqlalchemy import Column, Integer, String, create_engine, JSON
from sqlalchemy.orm import declarative_base

Base = declarative_base()
engine = create_engine(
    "sqlite:///example.db",
    connect_args={"check_same_thread": False},
)


class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    name = Column(String)
    data = Column(JSON)

Base.metadata.create_all(engine)  # Create tables

from fastapi import FastAPI
from sqladmin import Admin, ModelView

app = FastAPI()
admin = Admin(app, engine)


class UserAdmin(ModelView, model=User):
    column_list = [User.id, User.name]


admin.add_view(UserAdmin)
if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8080)

thank you Amin
I checked it again, it works well now.