Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_or_create() takes exactly 1 argument (2 given)

Last time I checked, (h) one argument:

for entry in f['entries']:
    h = {'feed':self, 'link': entry['link'],'title':entry['title'],
         'summary':entry['summary'],
         'updated_at':datetime.fromtimestamp(mktime(entry['updated_parsed']))}

    en = Entry.objects.get_or_create(h)

This code is failing with the error in the title. What can I check for?

like image 846
Michael Draper Avatar asked Dec 09 '22 06:12

Michael Draper


1 Answers

get_or_create takes keyword arguments only. If the arguments are in a dict, you can call it with:

en = Entry.objects.get_or_create(**h)

Or you can put the keyword arguments directly:

en = Entry.objects.get_or_create(name=value, ....)

The reason the error message told you that you supplied two arguments is that there is an implicit self parameter passed to the function.

like image 197
interjay Avatar answered Dec 27 '22 22:12

interjay