SmileyChris / django-countries

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Home Page:https://pypi.python.org/pypi/django-countries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about validation and or documentation.

cgte opened this issue · comments

commented

Currently i use django-countries with both raw data and clean data.

Unfortunately country codes do not seem to to be checked for validity.

it did the following to reproduce :

https://github.com/cgte/django-counrties-test/blob/main/sample/tests.py

how could we pre-validate data ? i wrote a sample cleaner function to sanitize input.

please let me know where it got things wrong and/or misunderstood.

I eventually found a point related to the issue :

https://github.com/cgte/django-countries/blob/main/django_countries/fields.py#L434

https://github.com/cgte/django-counrties-test/blob/87cdc0c3a556f75779b3b628e368e59f4a335124/sample/tests.py#L69

Maybe this is cause by not using modelForm in my import and/or test scripts ?

Model fields aren't implicitly validated when you save a model.

https://docs.djangoproject.com/en/5.0/ref/models/instances/#validating-objects

Note that full_clean() will not be called automatically when you call your model’s save() method. You’ll need to call it manually when you want to run one-step model validation for your own manually created models.