From the official documentation I can’t understand what is default parameter.
obj, created = Person.objects.get_or_create(first_name='John', last_name='Lennon',
defaults={'birthday': date(1940, 10, 9)}
Does it mean that it will look for fields which match both John and Lennon parameter and birthday will just insert? Can I use something else instead of defaults?
And what method should I use to clean all fields in table (models)?
It give me FileField error can not resolve keyword default in field
So I need look for fiels, if i found it – update datas. If i didn’t find it I have to crate new field… But, as I understud, It won’t update me default fields when finde present fields.
It’s quite obvious – if
get_or_createfinds queried object, thedefaultskeword does nothing. But if it creates object, then instance stored inobjhasbirthdayfield (in your example) filled with according value. You can pass any dictionary asdefaults, as long as its keys are valid field names for model you’re querying.To clean the whole table, you should use something like:
which is equivalent of:
To set some field in every object ( some column in every row ), there is
update()method:which translates to:
My sql is a bit rusty, but I believe it goes like that, more or less.