Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:47:19+00:00 2026-06-07T23:47:19+00:00

I am using Django ModelForms. I have a dropdown selector that allows users to

  • 0

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. For example,

In models.py

from django_countries import CountryField

class Booking(models.Model)
    name = models.charField(max_length=100)
    country = CountryField()

In views.py I want to be able to set a default selected item in the drop down menu, for example ‘United Kingdom’. I know how to do this with text fields, however cannot get it to work with the CountryField(). For example,

booking = BookingForm(initial={'name': 'mr majeika'}) //works
booking = BookingForm(initial={'country': 'United Kingdom'}) //does not work

I was hoping someone out there may be able to point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:47:21+00:00Added an answer on June 7, 2026 at 11:47 pm

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django model that I'm displaying as a form using a ModelForm.
I have a django form that allows a user to select multiple options: CARDS
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
Am using django forms on my app. I have a model Client like this:
I'm using Django's ModelForms and would like to have validation on both models and
I am using Django ModelForms to create a form. I have my form set
I'm new to Django and just trying to submit a form using ModelForms to
I am using webapp2, ndb model. I was trying to use django model forms
Using Django 1.1, I am trying to select the maximum value from a varchar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.