Code Monkey home page Code Monkey logo

Comments (2)

csvance avatar csvance commented on September 21, 2024

So I finally got it to work, but its ugly. I had to use the User SQLAlchemy instance and override its eq to check if the id fields were equal. The part where it checks if something should be selected does == between the user object populating the form and the one stored in form.select_field.data. That fails because they are different instances. However changing the comparison operator fixes the problem in this case.

class ApplicationModelView(ModelView):
  def create_form(self, obj=None)
    form = super().create_form(obj=obj)
    form.select_field.data = user_obj
    return form

class User(Base):
  def __eq__(self, other):
    return isinstance(other, type(self)) and self.id == other.id

Use this at your own risk, I have no idea if there are unintended consequences.

from flask-admin.

samuelhwilliams avatar samuelhwilliams commented on September 21, 2024

Are you able to provide a minimal reproduction code snippet for the problem you've flagged in the first post? Would be happy to investigate if this is still an issue; it feels like you shouldn't need to resort to JS or overriding __eq__.

from flask-admin.

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.