Create a view that returns json. At least if you want to use it in an ajax
way. Otherwise, I would recommend just passing it as an argument to the
templates that use it.
import json
def years(request):
return HttpResponse(json.dumps(dict(Model.YEAR_IN_SCHOOL_CHOICES)),
content_type=‘appl
In fact I want to convert all of these choises into json format and then
send them to user
thanks
On Thursday, May 17, 2018 at 8:46:42 PM UTC+4:30, C. Kirby wrote:
>
> if you just want to put that into json do:
> import json
>
> YEAR_IN_SCHOOL_CHOICES = (
> ('FR', 'Freshman'),
> ('SO', '
if you just want to put that into json do:
import json
YEAR_IN_SCHOOL_CHOICES = (
('FR', 'Freshman'),
('SO', 'Sophomore'),
('JR', 'Junior'),
('SR', 'Senior'),
)
serialized_year_choices = json.dumps(Model.YEAR_IN_SCHOOL_CHOICES)
On Thursday, May 17, 2018 at 10:52:15 AM UTC-4,
Hi,
I have a Field.choices in my model. lets say it is:
YEAR_IN_SCHOOL_CHOICES = (
> ('FR', 'Freshman'),
> ('SO', 'Sophomore'),
> ('JR', 'Junior'),
> ('SR', 'Senior'),
> )
I can access them using this method Model. YEAR_IN_SCHOOL_CHOICES but how
can I convert it to a json then I can send them
4 matches
Mail list logo