Skip to content

Commit

Permalink
diet records added to admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaafshar79 committed Jun 12, 2020
1 parent aea387e commit 580cf0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from flask_admin import Admin
from extentions import db
from users.models import User, UserModelView
from foods.models import Food, FoodModelView
from foods.models import Food, FoodModelView,DietRecord,DietRecordModelView
from blog.models import Post,PostModelView

admin = Admin(name='Dailydiet', template_mode='bootstrap3', url='/admin')
# adding models to admin
admin.add_view(UserModelView(User, db.session, endpoint='user_admin'))
admin.add_view(FoodModelView(Food, db.session, endpoint='food_admin'))
admin.add_view(PostModelView(Post, db.session, endpoint='post_admin'))
admin.add_view(DietRecordModelView(DietRecord,db.session,endpoint='diet_record_admin'))
8 changes: 8 additions & 0 deletions foods/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,13 @@ class DietRecord(db.Model):
diet = Column('diet', JSON(), nullable=False)


class DietRecordModelView(ModelView):
can_edit = True
column_display_pk = True
create_modal = True
edit_modal = True
column_labels = {'generatedAt': 'Generated At', 'diet': 'Diet ids'}


db.event.listen(db.session, 'before_commit', SearchableMixin.before_commit)
db.event.listen(db.session, 'after_commit', SearchableMixin.after_commit)

0 comments on commit 580cf0c

Please sign in to comment.