Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Using Databases in Python Gettin' CRUD-y With It View and Search Entries

Gilang Ilhami
Gilang Ilhami
12,045 Points

'SelectQuery' object is not callable

When i tried to view it, it returns an error and i'm not sure why

'SelectQuery' object is not callable 

codes

#!/usr/bin/env python3
from collections import OrderedDict
import datetime
import sys

from peewee import *


db = SqliteDatabase('diary.db')


class Entry(Model):
    content = TextField()
    timestamp = DateTimeField(default=datetime.datetime.now)

    class Meta:
        database = db

def initialize():
    """Create the database and the table if they don't exist"""
    db.connect()
    db.create_tables([Entry], safe=True)

def menu_loop():
    """Show the Menu"""

    choice = None

    while choice != 'q':
        print("Enter 'q'to quit.")
        for key, value in menu.items():
            print('{}) {}'.format(key, value.__doc__))

        choice = input('Action: ').lower().strip()

        if choice in menu:
            menu[choice]()

def add_entry():
    """Add an entry"""
    print("Enter your entry. Press ctrl+d when finished.")
    data = sys.stdin.read().strip()

    if data:
        if input("Save entry? [Y/n] ".lower()) != 'n':
                 Entry.create(content=data)
                 print("Saved successfully!")


def view_entries():
    """View previous entries."""
    entries = Entry.select().order_by(Entry.timestamp.desc())

    for entry in entries():
        timestamp = entry.timestamp.strftime('%A %B %b, %Y %I:%M%p')
        print(timestamp)
        print('='*len(timestamp))
        print(entery.content)
        print('n) next entry')
        print('q) return to main menu')

        next_action = input('Action: [N/q] ').lower().strip()
        if nest_action == 'q':
            break

def delete_entry(entry):
    """Delete an entry"""

menu = OrderedDict([
        ('a', add_entry),
        ('v', view_entries),

])


if __name__ == '__main__':
    initialize()
    menu_loop()
    ```