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
Amber Diehl
15,402 PointsChange in foreign key for SocialNetwork project
Kenneth Love thought you might want to know that there appears to be another change you might want to note for your Flask social network project.
I had this for the Post model, as shown in the video:
user = ForeignKeyField(
rel_model=User,
related_name='posts'
)
I was getting an error regarding wrong number of parms being passed for init. After doing some research, it appears the syntax has changed. I modified my model to this:
user = ForeignKeyField(User,
related_name='posts'
)
And the error disappeared and all was well.
2 Answers
Jeff Muday
Treehouse Moderator 28,732 PointsPeewee changed versions (currently at 3.0.x) since Kenneth Love recorded the video. I am not sure what version workspaces are tethered to. Workspaces "baked in" the Peewee library, so you can't check it with "pip freeze" like I do on my own development environment.
I dug into the source code--
https://github.com/coleifer/peewee/blob/master/peewee.py
In the source code, you can see what he slipped in there...
deprecated('"rel_model" has been deprecated in favor of ' '"model" for ForeignKeyField objects.')
also note:
deprecated('"related_name" has been deprecated in favor of ' '"backref" for Field objects.')
Note the dunder-init method. The first REQUIRED parameter after self, is model. So Peewee is going to complain if you use rel_model as the first parameter.
I recently corresponded with the author of Peewee, Charles Leifer to call his attention to another issue I discovered with Flask-Admin-- it wasn't a bug, but related to the version change. Some of the changes were to make Peewee naming and API more consistent with other ORMs. Charles is very talented and very helpful.
See below:
class ForeignKeyField(Field):
accessor_class = ForeignKeyAccessor
def __init__(self, model, field=None, backref=None, on_delete=None,
on_update=None, _deferred=None, rel_model=None, to_field=None,
object_id_name=None, related_name=None, *args, **kwargs):
super(ForeignKeyField, self).__init__(*args, **kwargs)
if rel_model is not None:
__deprecated__('"rel_model" has been deprecated in favor of '
'"model" for ForeignKeyField objects.')
model = rel_model
if to_field is not None:
__deprecated__('"to_field" has been deprecated in favor of '
'"field" for ForeignKeyField objects.')
field = to_field
if related_name is not None:
__deprecated__('"related_name" has been deprecated in favor of '
'"backref" for Field objects.')
backref = related_name
self.rel_model = model
self.rel_field = field
self.declared_backref = backref
self.backref = None
self.on_delete = on_delete
self.on_update = on_update
self.deferred = _deferred
self.object_id_name = object_id_name
Amber Diehl
15,402 PointsJeff Muday thanks for your detailed reply!
I neglected to say that I was not using workspaces when following this course. But thought it still worth noting since his teacher notes included other changes (e.g. authenticated being changed from method to property).