Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed field #5

Closed
litnimax opened this issue Aug 3, 2015 · 3 comments
Closed

Computed field #5

litnimax opened this issue Aug 3, 2015 · 3 comments

Comments

@litnimax
Copy link

litnimax commented Aug 3, 2015

I have a question on how to implement a computed field.

For example, I'd like to add such a field to column_list, smth like that:

class UserProfile(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode(128))
    admin = db.Column(db.Boolean, index=True)

   def get_name_ex(self):
        return '%s (admin: %s)' % (self.name, self.admin)

...
class UserProfileAdmin(ModelView, AuthBaseView):
    column_list = ['get_name_ex']

But this does not work as expected.
Please advise.

@mrjoes
Copy link
Owner

mrjoes commented Aug 3, 2015

Make it a property, either generic python one or a SQLAlchemy hybrid property.

@litnimax
Copy link
Author

litnimax commented Aug 3, 2015

Hm.. Tried to make a propery. Will try again.
Also found probably a solution with column_formatters - http://www.paulsprogrammingnotes.com/2014/03/checkmark-columnformatters-flask-admin.html
Thanks.

@litnimax
Copy link
Author

litnimax commented Aug 4, 2015

No need for a property in my case - just format a column like here http://stackoverflow.com/questions/17174707/can-model-views-in-flask-admin-hyperlink-to-other-model-views
Thanks.
Please close it.

@litnimax litnimax closed this as completed Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants