Git Product home page Git Product logo

flask-superadmin's Introduction

Flask-SuperAdmin

Join the chat at https://gitter.im/syrusakbary/Flask-SuperAdmin https://travis-ci.org/SyrusAkbary/Flask-SuperAdmin.png?branch=master

Flask-Superadmin is the best admin interface framework for Flask. As good as Django admin.

Batteries included:

  • Admin interface
  • Scaffolding for MongoEngine, Django and SQLAlchemy
  • File administrator (optional)

Requirements:

Admin interface

Influenced heavily by the Django admin, provides easy create/edit/delete functionality for your project's models (MongoEngine, Django or SQLAlchemy).

https://raw.github.com/SyrusAkbary/Flask-SuperAdmin/master/screenshots/model-list.png https://raw.github.com/SyrusAkbary/Flask-SuperAdmin/master/screenshots/model-edit.png

Introduction

This is library for building administrative interface on top of Flask framework.

Instead of providing simple scaffolding for SQLAlchemy, MongoEngine or Django models, Flask-SuperAdmin provides tools that can be used to build administrative interface of any complexity, using consistent look and feel.

Small example (Flask initialization omitted):

from flask.ext.superadmin import Admin, model

app = Flask(__name__)
admin = Admin(app)

# For SQLAlchemy (User is a SQLAlchemy Model/Table)
admin.register(User, session=db.session)

# For MongoEngine Documents (User is a MongoEngine Document)
admin.register(User)

# For Django Models (User is a Django Model)
admin.register(User)


# Adding a custom view
admin.add_view(CustomView(name='Photos', category='Cats'))

admin.setup_app(app)

Installation

For installing you have to do:

pip install Flask-SuperAdmin

Or:

python setup.py install

Examples

Library comes with a lot of examples, you can find them in examples directory.

Documentation

Flask-SuperAdmin is extensively documented, you can find documentation here.

3rd Party Stuff

Flask-SuperAdmin is built with help of Twitter Bootstrap, Chosen, and jQuery.

Kudos

This library is a supervitamined fork of the Flask-Admin package by Serge S. Koval.

flask-superadmin's People

Contributors

ba0f3 avatar briancappello avatar burhan avatar daniellawrence avatar dbluestein avatar deepwalker avatar denniseijpe avatar devxoul avatar dmedvinsky avatar dorianux avatar g4b1nagy avatar gitter-badger avatar hardtack avatar itrurl avatar iurisilvio avatar javaguirre avatar jbremer avatar jpvanhal avatar martyanov avatar mrjoes avatar noirbizarre avatar nosovsh avatar plaes avatar psykzz avatar rochacbruno avatar sv1jsb avatar syrusakbary avatar tonyseek avatar wilsaj avatar wojcikstefan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-superadmin's Issues

Custom actions

I want to create custom actions. Looks like it is not implemented yet.

Get SQLAlchemy session from app when Flask-SQLAlchemy

When using Flask-SQLAlchemy, it is possible to get session information from app. Makes sense to create an easy integration to it, but ModelAdmin does not have an app reference.

sqlalchemy_state = app.extensions.get('sqlalchemy')
session = sqlalchemy_state.db.session

I don't know a good way to do it.

Issue with collection_class in relationship

Hi!

I'm trying to implement a similar model from the following simple example:
http://docs.sqlalchemy.org/en/rel_0_9/_modules/examples/adjacency_list/adjacency_list.html

When I add the "collection_class=attribute_mapped_collection('name')" to the children relationship, superadmin fails with the following error when adding a new row

Traceback (most recent call last):
  File "/home/boden/nextgame-env/site-packages/flask_superadmin/model/base.py", line 242, in add
    instance = self.save_model(self.model(), form, adding=True)
  File "/home/boden/nextgame-env/site-packages/flask_superadmin/model/backends/sqlalchemy/view.py", line 67, in save_model
    form.populate_obj(instance)
  File "/home/boden/nextgame-env/site-packages/wtforms/form.py", line 79, in populate_obj
    field.populate_obj(obj, name)
  File "/home/boden/nextgame-env/site-packages/wtforms/fields/core.py", line 298, in populate_obj
    setattr(obj, name, self.data)
  File "/home/boden/nextgame-env/site-packages/sqlalchemy/orm/attributes.py", line 220, in __set__
    instance_dict(instance), value, None)
  File "/home/boden/nextgame-env/site-packages/sqlalchemy/orm/attributes.py", line 975, in set
    lambda adapter, i: adapter.adapt_like_to_iterable(i))
  File "/home/boden/nextgame-env/site-packages/sqlalchemy/orm/attributes.py", line 991, in _set_iterable
    new_values = list(adapter(new_collection, iterable))
  File "/home/boden/nextgame-env/site-packages/sqlalchemy/orm/collections.py", line 1533, in _convert
    for incoming_key, value in util.dictlike_iteritems(dictlike):
  File "/home/boden/nextgame-env/site-packages/sqlalchemy/util/langhelpers.py", line 1032, in dictlike_iteritems
    "Object '%r' is not dict-like" % dictlike)
TypeError: Object '[]' is not dict-like

It looks like the Flask-Admin people had a similar issue a while back if that gives any clues:
https://github.com/mrjoes/flask-admin/issues/275

Pagination is broken

The pagination container doesn't appear and the "Total count" show only the page size.

Error when viewing an object on SQLAlchemy model admin

Here's a traceback when trying to edit one of my models:

  File "/Users/fermigier/envs/dev/src/flask-superadmin/flask_superadmin/model/base.py", line 263, in edit
    Form = self.get_form(include_readonly=request.method == 'GET')
  File "/Users/fermigier/envs/dev/src/flask-superadmin/flask_superadmin/model/base.py", line 118, in get_form
    converter=converter)
  File "/Users/fermigier/envs/dev/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 303, in model_form
    converter)
  File "/Users/fermigier/envs/dev/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 241, in model_fields
    field_args.get(name), db_session)
  File "/Users/fermigier/envs/dev/src/flask-superadmin/flask_superadmin/model/backends/sqlalchemy/orm.py", line 155, in convert
    kwargs)
  File "/Users/fermigier/envs/dev/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 84, in convert
    if callable_default and callable(callable_default):
  File "/Users/fermigier/envs/dev/lib/python2.7/site-packages/sqlalchemy/sql/expression.py", line 1803, in __nonzero__
    raise TypeError("Boolean value of this clause is not defined")
TypeError: Boolean value of this clause is not defined

PyJade templates?

Just curious if any plans/code exists?
And if not, would there be any interest in eventual pull requests?
Thanks!

Sqlalchemy ModelAdmin "fields" attribute ignored

I investigated this issue and i found out that the latest FlaskSuperAdmin version on the Python cheese shop (pypi) ie. the one installed via pip is not the same as the one on the current master branch - which is the one reflected by the documentation.

The one installed, has an attribute called only, which is taken into account by the get_form method, which is also different.

The get_form method in the model.base.BaseModelAdmin class has different signatures in both version.

The earlier version (which takes into account self.only in computing the only fields to include during form computation) has this signature:

def get_form(self, include_readonly=False):

While the newer version (uses fields attribute to compute the only fields to include in the form) has this signature:

def get_form(self):

The docs refer to the new version - which is not the one installed by pip install Flask-SuperAdmin

Bug when adding/modifying an integer field with value 0.

There's a bug where if I'm adding or modifying an integer field with the value 0, that it flashes a "No value entered" message (or something along these lines.)
I quickly looked at the problem a few weeks ago, and it's related to using the incorrect validator or so, which results in a "if not value:" statement, which naturally should be more along the lines of "if value is None:".

Thanks for the plugin :)

New versions

Why there is still no new minor versions of the package in repositories?
There are many fixes that have been applied since version 1.7

Need a way to use flask-security wrapped flask-login

Hi, I'm using flask superadmin and I like what I see. However, I need admin views to be protected. I'm using flask-security with mongoengine. Is there a way that I can get the admin to be protected using the flask-login from flask-security?

The typical method is to use the login_required decorator which can be used directly:

@login_required

or in class-based views such as:

from flask.views import MethodView
from flask_security import login_required

class ListView(MethodView):
    decorators = [login_required]

Thanks!

field_overrides TypeError 'dict' object not callable

Hello,

So I am trying to use superadmin to change the label (I want to change the default value eventually, but I am making small steps...) of a field. And I saw in the source code that if I use the field_overrides attribute I could do this... so here is my code:

class ProjectsModel(model.ModelAdmin):
  session = db.session
  field_overrides = { 
                      'created_at': { 'label': 'blabla' }
                    }

but this throws the following error:

TypeError: 'dict' object is not callable

on

File ".../venv/lib/python2.7/site-packages/flask_superadmin/model/backends/sqlalchemy/orm.py", line 150, in convert

Display the sourcecode for this frameOpen an interactive python shell in this framereturn override(**kwargs)

Am I doing something wrong? I am following the exact example posted in the comments, through the code...

Thanks,
Vlad

How to handle read only fields in add view

The commit ab23b39 broke the add view when the model has readonly fields. It happens because the form exclude readonly fields. It is fine to the edit view, but does not work to add view.

Should we split the model_form in something like edit_model_form and add_model_form or we have a better solution to it?

Excluding a field results in AttributeError.

The error:

Traceback (most recent call last):
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/base.py", line 37, in inner
    return f(self, *args, **kwargs)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 325, in edit
    Form = self.get_form()
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 177, in get_form
    converter=converter)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/flask_superadmin/model/backends/sqlalchemy/orm.py", line 178, in model_form
    converter=converter)
  File "/home/robin/github/ieee/venv/lib/python2.7/site-packages/wtforms/ext/sqlalchemy/orm.py", line 289, in model_form
    exclude.append(prop.key)
AttributeError: 'tuple' object has no attribute 'append'

My user class.

And my Admin Views:

class MyAdminIndexView(AdminIndexView):          
    def is_accessible(self):                     
        return current_user.is_authenticated() \ 
            and current_user.get_role() != 'user'

# Limit view to only officers and admin.         
class MyAdminView(ModelAdmin):                   
    def is_accessible(self):                     
        return current_user.is_authenticated() \ 
            and current_user.get_role() != 'user'

class UserView(MyAdminView):                

    session = db.session                    
    #readonly_fields = ('password',)        
    exclude = ('password',)                 
    list_display = ('name', 'email', 'role')

Check out the __init.py__ to see how the views are added.

Some MongoEngine models cannot be saved (despite not having disallowed fields)

Failed to edit model. 'unicode' object has no attribute 'items'

Here I've tried to save a model that consisted purely of basic fields (no ObjectID, no Reference fields).

The only potentially unusual thing about this model is that it does have a property. But that shouldn't affect the commit pipeline. (I would hope anyway...)

nosetests run only test_base

When I run nose from project root, it discovers 12 tests (only test_base.py). When I run nose from flask_superadmin, it discovers 25 tests.

I have no idea why it is happening.

I checked travis, it ran only 12 tests.

Update Bootstrap to v3.0.2

Bootstrap's latest and greatest edition is 3.0.2. Please update the CSS to reflect the change in framework.

error running examples

$ python simple.py
Traceback (most recent call last):
File "simple.py", line 3, in
from flask.ext import superadmin
File "/home/erik/.virtualenvs/tmp/local/lib/python2.7/site-packages/flask/exthook.py", line 62, in load_module
import(realname)
File "/home/erik/.virtualenvs/tmp/local/lib/python2.7/site-packages/flask_superadmin/init.py", line 2, in
from model import ModelAdmin
File "/home/erik/.virtualenvs/tmp/local/lib/python2.7/site-packages/flask_superadmin/model/init.py", line 1, in
from .base import ModelAdmin, AdminModelConverter
File "/home/erik/.virtualenvs/tmp/local/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 10, in
from flask_superadmin.form import BaseForm, ChosenSelectWidget, DatePickerWidget,
File "/home/erik/.virtualenvs/tmp/local/lib/python2.7/site-packages/flask_superadmin/form.py", line 115, in
class FileField(wtf.FileField):
AttributeError: 'module' object has no attribute 'FileField'

Question about changing field type (and default)

Hello,

I have a field that I want to be of type TextArea (in the db it is stored as Unicode string) and that will accept whitespace (basically like a raw text field where I can put new lines and such).

I've been looking around for a while and I can't see to figure it out, sorry...

Also, for a 'created_at' field, I would like to give it a default value so that I don't have to always fill it in. I added this:

class ProjectsModel(model.ModelAdmin):
  session = db.session
  field_args = { 
                  'created_at': { 'default': datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") }
               }

but it doesn't seem to do anything...

Thank you,
Vlad

List view does not work with SQLAlchemy

Looks like SQLAlchemy models does not have a pk field. To access the primary key, use column_value.__mapper__.primary_key[0].name, but it can have some problem with composite primary keys.

Traceback (most recent call last):
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 36, in inner
    return f(self, *args, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/model/base.py", line 290, in list
    search_query=search_query)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/base.py", line 169, in render
    return render_template(template, **kwargs)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/templating.py", line 125, in render_template
    context, ctx.app)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/flask/templating.py", line 107, in _render
    rv = template.render(context)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/opt/leadpj.pricez.com.br/venv/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/model/list.html", line 3, in top-level template code
    {% set name = admin_view.get_display_name() %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/layout.html", line 21, in top-level template code
    {% block page_body %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/layout.html", line 71, in block "page_body"
    {% block body %}{% endblock %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/templates/admin/model/list.html", line 81, in block "body"
    {% with reference = admin_view.get_reference(admin_view.get_column(instance, c)) %}
  File "/opt/leadpj.pricez.com.br/venv/src/flask-superadmin/flask_superadmin/model/base.py", line 128, in get_reference
    return '/admin/%s/%s/' % (model_view.endpoint, column_value.pk)
AttributeError: 'Endpoint' object has no attribute 'pk'

Selecting all rows for foreign keys.

When adding or modifying a row which has a foreign key there's a dropdown box (which is a nice idea - although it'd be even more awesome if I can specify a way to search through all rows of this particular table) but it fetches all rows from the table.
You can imagine this doesn't really work well when you have a foreign key in a table with a few million rows.. ;)

Nested Fields at example of picture #2

Hi,

I'm having a really hard time figuring out how to add nested fields into a form. I saw this on the second picture in the readme. Can you give me an example of how to get this?

SS

Thanks

Accept null in nullable fields

I have a SQLAlchemy model with a nullable=True DateTime column. I can't add a new object without fill this field.

I didn't tested it with other column types yet.

flask-admin

I'm just curious if you think it could make sense for flask-superadmin and flask-admin to be rolled into one project? are the goals the same?
seems like a shame to have duplicated efforts especially since neither project/community is super large

Travis CI configuration

I think Travis CI account should be controlled by the maintainer. Now it's linked to my account.

ProgrammingError when searching for records

Hello,
I am trying to search for a record in the record list page and I am getting back this message:

ProgrammingError: (ProgrammingError) operator does not exist: integer + boolean
LINE 4: WHERE 0 + (email LIKE '%' || '[email protected]' || '%')) AS an...

The column I am searching is declared with search_fields at the ModelAdmin class.
I am using Sqlalchemy.

Any help will be much appreciated.

Thank you very much
Andreas

AttributeError: 'NoneType' object has no attribute 'choices'

I get an attribute error like this:

AttributeError
AttributeError: 'NoneType' object has no attribute 'choices'

Traceback (most recent call last)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/base.py", line 36, in inner
return f(self, _args, *_kwargs)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/base.py", line 36, in inner
return f(self, _args, *_kwargs)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/base.py", line 36, in inner
return f(self, _args, *_kwargs)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 278, in edit
Form = self.get_form(include_readonly=request.method == 'GET')
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 132, in get_form
converter=converter)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/backends/mongoengine/orm.py", line 300, in model_form
field_dict = model_fields(model, only, exclude, field_args, converter)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/backends/mongoengine/orm.py", line 223, in model_fields
field = converter.convert(model, model_field, field_args.get(name))
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 17, in convert
field = super(AdminModelConverter, self).convert(_args, *_kwargs)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/backends/mongoengine/orm.py", line 72, in convert
return self.converters[ftype](model, field, kwargs)
File "/Users/tianyu/.virtualenvs/dealpick/lib/python2.7/site-packages/flask_superadmin/model/backends/mongoengine/orm.py", line 155, in conv_List
if field.field.choices:
AttributeError: 'NoneType' object has no attribute 'choices'

I do not know how to fix it,can u help me ?
This is my model used mongoengine v0.8.1:

class Deal(Document, IncludeUniqueIDField):
    site         = StringField()
    key          = StringField()
    url          = StringField()

    title        = StringField()
    description  = StringField()
    price        = StringField()
    list_price   = StringField()
    image        = ListField()

    shipping     = StringField()
    manufacturer = StringField()
    expired      = BooleanField()
    is_hot       = BooleanField()

    score        =   FloatField(default=0)
    posted_at    =   DateTimeField()
    created_at   =   DateTimeField(default=datetime.utcnow)
    updated_at   =   DateTimeField()
    ublished_at  =   DateTimeField()

    visible      =   BooleanField(default=True)

    meta = {
        'indexes': [('site', 'key')],
    }


and the flask-superadmin is latest version.

Error on SQLAlchemy model admin

I get the following error:

TypeError: get_queryset() takes no arguments (1 given)

on:

flask_superadmin/model/backends/sqlalchemy/view.py", line 92, in get_list

My code is pretty straightforward from the tutorial:

...
superadmin.register(User, session=db.session)
...

Can't override default index view

As stated here: https://github.com/SyrusAkbary/Flask-SuperAdmin/blob/master/flask_superadmin/base.py#L198

I am doing this:

class MyHomeView(AdminIndexView):
    @expose('/')
    def index(self):
        return render_template('adminhome.html')

admin = Admin(index_view=MyHomeView)
admin.init_app(app)

What I get:

Traceback (most recent call last):
  File "./run.py", line 3, in <module>
    from test import app
  File "/Users/g/test/test/__init__.py", line 48, in <module>
    admin.init_app(app)
  File "/Users/g/test/lib/python2.7/site-packages/flask_superadmin/base.py", line 448, in init_app
    app.register_blueprint(view.create_blueprint(self))
TypeError: unbound method create_blueprint() must be called with MyHomeView instance as first argument (got Admin instance instead)

Allow form field order to be set by user in Edit View

I couldn't find this looking through the source or documentation but is it possible to customize the order of the form fields in the Edit view in Flask-Superadmin?

So right now, in the Edit View, the form fields are in random order and I would like to organize it a bit so they make logical sense.

For example, instead of it showing a possible address form in the order [city, address, zipcode], I would like to organize it to [address, city, zipcode].

Exception: Flask-SuperAdmin is already associated with an application.

It seems that flask-superadmin doesn't work with multiple Flask application instances at once. I use Application Factories pattern to create application as needed to aid unittests and to support multiple configurations.

def init_app(self, app):
    """
        Register all views with Flask application.

        `app`
            Flask application instance
    """
    if self.app is not None:
        raise Exception('Flask-SuperAdmin is already associated with an application.')

Cannot inherit from ModelAdmin

TypeError: __new__() takes at least 3 arguments (2 given)

Where I have defined a protected ModelAdmin class that looks something like this:

class ProtectedModelAdmin(ModelAdmin):
    def is_accessible(self):
        if g.user is None:
            return False
        return g.user.admin

And subsequently used it like this:

class UserModel(ProtectedModelAdmin):
    list_display = ('email', 'first_name', 'last_name', 'creation_date')


admin.register(User, UserModel)

Routing

When I run the admin on "/", all the paths are broken, both the static and app routing.

Code:

from flask import Flask
from flask.ext.superadmin import Admin
from mongoengine import Document, StringField, connect

app = Flask(__name__)
app.config['SECRET_KEY'] = 'da79dg7asd87agsd8a'

mongodb_settings = {
    'db':'test',
}
connect(**mongodb_settings)

class User(Document):
    username = StringField(unique=True)
    email = StringField(unique=True)

if __name__ == '__main__':
    admin = Admin(app, url="/")
    admin.register(User)
    app.debug = True
    app.run('0.0.0.0', 8000)

Model view has fields out of order.

Originally, I thought the view would alphanumerically sort the fields but it appears to be quite random.

Here's the schema for a post object:

class Post(db.Model):                                            
    id = db.Column(db.Integer, primary_key=True)                 
    title = db.Column(db.String(120))                            
    content = db.Column(db.Text, nullable=False)                 
    date = db.Column(db.DateTime)                                
    sticky = db.Column(db.Boolean())                             
    username = db.Column(db.String(50), db.ForeignKey(User.name))
    image_one = db.Column(db.String(2083))                       
    image_two = db.Column(db.String(2083))                       
    image_three = db.Column(db.String(2083))                     
    image_four = db.Column(db.String(2083))                      
    tags = db.relationship('Tag', secondary=post_tags_table)     

And here's a screenshot of the admin view:

good APP

I used this in my project,it's wonderful,but I do not know what is the diffrient about this one and Falsk-Admin.

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.