What I need:
I want to get object details from DB. I use get() function. The problem I have is, that I make in in a function, and one of the arguments is field name as string:
def delete_file_if_changed(id, change, form, model, field_name='image'):
if change:
if field_name in form.changed_data:
old_image = model.objects.get(pk__exact=id)
Now – how can I do the thing that I can get old_image.field_name – how to do that?
You know, I thought this was your answer at first — it lets you search by a dynamic property: Could the
**operator work?But, if you already have the object you want, and you just need to get the value of a dynamically named property, then you can use
getattr(object, name[, default]):