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

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Building a social network with Flask - updating user details (extra credit)

Hi everyone.

I am dealing with the extra credit right before the final stage in the Create a social Network with Flask course.

Please find my workspace snapshot here: https://w.trhou.se/mwi9cnp8qh

What I have done so far:

1) in forms.py I have created a DetailsChangeForm simply extending the RegisterForm we already had; a big part of it is commented out for testing purposes.

2) in the model.py file I have added a method for the update.

3) In the app.py I have added the route and the relative code for the function. Please note that I haven't added a link to the update_details page yet, I access it by appending update_details to the initial url.

The problem: When I actually try to update the username I get a peewee error: "column username is not unique". I have had a look at peewee's docs and some threads on stackoverflow but more than the code itself I am struggling understanding with this is creating another username column.

I presume the problem needs to be here:

User.update(username=username).where(User.username == current_user.username).execute()

Especially I imagine the username=username does not make much sense to the compiler, but I have to update the User.username stored value with my new username value, and if I go with User.username=username peewee complains about referencing the keyword...

I am new to databases, all I know (well pretty much know) is from Andre's db foundation course and our other python peewee course.

Any help would be much appreciated.

Vittorio

PS -> Thanks Treehouse for the newly introduced workspaces snapshops!