Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with object own __init__ and Query method #40

Closed
gabgir opened this issue May 8, 2014 · 2 comments
Closed

Bug with object own __init__ and Query method #40

gabgir opened this issue May 8, 2014 · 2 comments

Comments

@gabgir
Copy link

gabgir commented May 8, 2014

Hi,

I'm still a bit new to Python and after creating a class with its own __init__ method, the Query method doesn't work properly. If a comment my __init__ method, then the object get retrieve properly. I suppose my __init__method override something in the Object class, But it is fairly basic as you can see:

def __init__(self, name):
    self.name = name
    self.tasks = []
    List.listcount = List.listcount + 1

And the retrieving code is also pretty simple:

mylists = List.Query.all()
for mylist in mylists:
    print mylist.name
    print mylist.tasks

I could rewrite everything to not use my own __init__ method, but I would like not to do that as it keeps my code easier to understand. Any ideas on how to fix that? Thanks.

@dgrtwo
Copy link
Collaborator

dgrtwo commented May 8, 2014

Please see my StackOverflow answer here for a simple workaround. In short you need to alter your __init__ so that it takes **kwargs, then add Object.__init__(self, **kwargs) to the end of your __init__.

@dgrtwo dgrtwo closed this as completed May 8, 2014
@gabgir
Copy link
Author

gabgir commented May 8, 2014

Thanks for the quick answer! I should have checked StackOverflow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants