django countries dropdown default

后端 未结 1 1294
故里飘歌
故里飘歌 2021-01-25 08:14

I am using Django ModelForms. I have a dropdown selector that allows users to select the country. The country is part of the booking model and is defined using django_countries

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-25 08:25

    According to here:

    http://pypi.python.org/pypi/django-countries/1.0.1

    "CountryField is based on Django's CharField, providing choices corresponding to the official ISO 3166-1 list of countries (with a default max_length of 2)"

    And the complete list of the CountryField here:

    http://djangosnippets.org/snippets/1476/

    Can you try this and see if it works?

    booking = BookingForm(initial={'country': 'GB'})
    

    0 讨论(0)
提交回复
热议问题