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 trialThanitsak Leuangsupornpong
7,490 PointsHow to give a textfield attribute named order.
Thanks for answer my question!
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
33,371 PointsHello 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.
;)
Vittorio Somaschini
33,371 PointsHello 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
7,490 PointsThanks 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
Treehouse Guest TeacherFields are instances of classes and classes have CamelCased names. So you wouldn't have textfield
, you'd have TextField
.
Thanitsak Leuangsupornpong
7,490 PointsThanks 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!
Thanitsak Leuangsupornpong
7,490 PointsThanitsak Leuangsupornpong
7,490 PointsI finished it already,Thanks you very much for your help! :D