Re: Meta question

2019-09-11 Thread ANi
:-)  glad to help


Mike Dewhirst於 2019年9月10日星期二 UTC+8下午4時27分06秒寫道:
>
> Given a model instance and the name of one of its fields as a string, 
> how can I get/put a value in that field? 
>
> The methods might look like this ... 
>
> def get_value(obj, fldname): 
>
>  ... 
>
>  return value 
>
> def put_value(obj, fldname, value): 
>
>  pass 
>
>
> Thanks for any hints 
>
> Mike 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e0dacac3-94cc-4b22-8266-b9b4ad30c014%40googlegroups.com.


Re: Re: Meta question

2019-09-11 Thread Mike Dewhirst

Thank you Ani - works nicely :)

Cheers

Mike

On 10/09/2019 6:59 pm, ANi wrote:

getattr(instance, key) to get the value
setattr(instance, key ,value) to put the value, and remember to do 
instance.save() otherwise it won't actually be changed.

Mike Dewhirst於 2019年9月10日星期二 UTC+8下午4時27分06秒寫道:

Given a model instance and the name of one of its fields as a string,
how can I get/put a value in that field?

The methods might look like this ...

def get_value(obj, fldname):

 ...

 return value

def put_value(obj, fldname, value):

 pass


Thanks for any hints

Mike


-- You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abe0c993-6cf5-4a55-9d3b-9dd213cad8db%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e43da3c-c3bf-8833-2c7d-51d201b3ce25%40dewhirst.com.au.


Re: Meta question

2019-09-10 Thread ANi
getattr(instance, key) to get the value 
setattr(instance, key ,value) to put the value, and remember to do 
instance.save() otherwise it won't actually be changed.
 
Mike Dewhirst於 2019年9月10日星期二 UTC+8下午4時27分06秒寫道:
>
> Given a model instance and the name of one of its fields as a string, 
> how can I get/put a value in that field? 
>
> The methods might look like this ... 
>
> def get_value(obj, fldname): 
>
>  ... 
>
>  return value 
>
> def put_value(obj, fldname, value): 
>
>  pass 
>
>
> Thanks for any hints 
>
> Mike 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/abe0c993-6cf5-4a55-9d3b-9dd213cad8db%40googlegroups.com.