0

I have below model:

class Flower(models.Model):
    name     =  models.CharField(max_length=30)
    country  =  # I don't know 
    province =  # I don't know

What is the best practice for implementing hierarchical country and province fields in models? I want that the user can select some countries and provinces from the list, and later he can add or remove them. also when the user select for example Germany from the country field, only provinces related to Germany will show in the province select box field. The user is able to select some countries and provinces

Darwin
  • 1,695
  • 1
  • 19
  • 29

1 Answers1

0

Simplest way is add javascript code on page which will be catch "country" event, and then loads data in to your selectboxes and according to country your JS will filter the province.

for country you can use Django Country

from django_countries.fields import CountryField

class Foo(models.Model):
    country = CountryField()
Prabhat
  • 3
  • 3