Coder Social home page Coder Social logo

Comments (6)

aminalaee avatar aminalaee commented on June 16, 2024 1

@okapies After the PR was merged you should be able to override this behaviour by setting form_overrides.
But I see you've proposed a solution which might be simpler, I will take a look next week. Thank you for the contribution.

from sqladmin.

aminalaee avatar aminalaee commented on June 16, 2024

Hi,
To be honest, I think we should first start integrating SQLModel first, and see how it goes.
After that we can decide to allow custom converters and how we can approach that.

Thanks for the suggestion.

from sqladmin.

aminalaee avatar aminalaee commented on June 16, 2024

I've created a PR for SQLModel support, but I think this will solve the issue here too.
#94

Basically this will enable classes inheriting from TypeDecorator and handle them properly.

from sqladmin.

lovetoburnswhen avatar lovetoburnswhen commented on June 16, 2024

Nice! However the PR does break sqlalchemy_utils.types.ChoiceType

  File "/Users/app/.venv/lib/python3.9/site-packages/sqladmin/models.py", line 635, in scaffold_form
    return await get_model_form(
                 └ <function get_model_form at 0x104e04a60>
  File "/Users/app/.venv/lib/python3.9/site-packages/sqladmin/forms.py", line 297, in get_model_form
    field = await converter.convert(
                  │         └ <function ModelConverterBase.convert at 0x104e1b550>
                  └ <sqladmin.forms.ModelConverter object at 0x1078f2fa0>
  File "/Users/app/.venv/lib/python3.9/site-packages/sqladmin/forms.py", line 105, in convert
    converter = self.get_converter(prop)
                │    │             └ <ColumnProperty at 0x105a27240; schedule_type>
                │    └ <function ModelConverterBase.get_converter at 0x104e1b4c0>
                └ <sqladmin.forms.ModelConverter object at 0x1078f2fa0>
  File "/Users/app/.venv/lib/python3.9/site-packages/sqladmin/forms.py", line 75, in get_converter
    if col_type.impl.__name__ in self.converters:  # type: ignore
       │        │                │    └ {'Boolean': <bound method ModelConverter.conv_Boolean of <sqladmin.forms.ModelConverter object at 0x1078f2fa0>>, 'dialects.ms...
       │        │                └ <sqladmin.forms.ModelConverter object at 0x1078f2fa0>
       │        └ Unicode(length=255)
       └ <class 'sqlalchemy_utils.types.choice.ChoiceType'>

AttributeError: 'Unicode' object has no attribute '__name__'

One benefit of being able to register custom converters is so that you can bypass the usual ModelConverter flow. Passing in form_overrides doesn't work either since it tries to get the converter before it looks at override

from sqladmin.

okapies avatar okapies commented on June 16, 2024

It seems this issue has not been solved yet, right? I need to add my converter to support the custom column types. @aminalaee

ref. #176.

from sqladmin.

okapies avatar okapies commented on June 16, 2024

Thanks, I'll try it. IMHO, I think it may be useful if ModelAdmin accepts converters setting (type -> ConverterCallable or column -> ConverterCallable?) that customizes ModelConverter.

from sqladmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.