Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Build a Social Network with Flask Broadcasting Lunch Order Model

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

How to give a textfield attribute named order.

Thanks for answer my question!

models.py
import datetime

from flask.ext.bcrypt import generate_password_hash
from flask.ext.login import UserMixin
from peewee import *

DATABASE = SqliteDatabase(':memory:')


class User(UserMixin, Model):
    email = CharField(unique=True)
    password = CharField(max_length=100)
    join_date = DateTimeField(default=datetime.datetime.now)
    bio = CharField(default='')

    class Meta:
        database = DATABASE

    @classmethod
    def new(cls, email, password):
        cls.create(
            email=email,
            password=generate_password_hash(password)
        )


@classmethod
def LunchOrder():
    content = TextField()


def initialize():
    DATABASE.connect()
    DATABASE.create_tables([User], safe=True)
    DATABASE.close()

2 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Thanitsak.

Please doublecheck the requirements of the code challenge, they want an "order" field for this calls, not a "content" field.

Camel case is for example the TextField you wrote, where every single name starts with a capital letter even if we actually write a single word. Please note that in python names normally look like this: "text_field", while, using the camel case, they look something like this: TextField.

This is just to give you an idea.

Vittorio

PS edited for readability. Thanitsak Leuangsupornpong , please have a look at this thread to see how Treehouse recommend to past code into the forum: https://teamtreehouse.com/forum/posting-code-to-the-forum I am pretty sure this will come handy when you will have to post longer pieces of code.

;)

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

I finished it already,Thanks you very much for your help! :D

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Thanitsak.

You actually need to sort out a couple of things here.

First the decorator ("@classmethod") is not needed as this will only be a class.

Also, please note that the keyword for creating the class is actually "class" and not def. Plus, since we need this class a new Model class, we need to put Model inside the parenthesis.

Task 2/3 is very similar, let me know if any problems.

Vittorio

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Thanks for answer, but how to create the text field,it said textfield is not defined.

What I did is 'content = textfield(order)'

Thanks!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Fields are instances of classes and classes have CamelCased names. So you wouldn't have textfield, you'd have TextField.

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Thanks for answer! But it still didn't work when I did

class LunchOrder(Model):
    content = TextField('order')

I changed to TextField already. It said LunchOrder model doesn't have an order field

And what did you mean camel classes names.

Thanks you very much for answer!