Select existing data or creating a new one, with Django forms

18 views
Skip to first unread message

João Luiz Lorencetti

unread,
Jul 23, 2015, 6:02:09 AM7/23/15
to Django users
My model have a field called 'city', it's a foreign key to City model.

The user have the option to select a city in a dropdown menu (Select widget), or click in a button and write the name of a new (not present in the database) city.

Using a ModelForm, I added an extra field called 'new_city' to my form, after that I wrote this clean method: https://gist.github.com/dirtycoder/73b70ae6f94acf215e61

I'm new to Django and writing my first "real" web app so I can be missing some concept about forms and validation.

Is this the best way to accomplish what I want?

Thanks!
Reply all
Reply to author
Forward
0 new messages