Carlobo, If you want the nation field to be given a value as soon as a a dialing prefix is entered, without posting the page to the web server and retrieving a new page, you're going to have to use _javascript_ and the perhaps the technique called Ajax. Django and its Python code run only on the server, not in the browser. So, it cannot fill in one field based on another, except by posting the partially completed form to the server and having it sent back with the one additional field filled in. The disadvantages of this approach include: - Slower than the approaches described below - Harder to preserve the user's context in the Web page (which field had the keyboard focus, how far down the page was scrolled, etc.) - May place a heavier load on the server If you want to use _javascript_, you can include the _javascript_ code in an HTML <script> tag in a Django template, or in a separate JS file referred to by an HTML <script> tag in a Django template. The JS code could include a JS map of dialing prefixes to nations, and could look up the nation value locally in that map and assign it to the nation field in response to a JS "change" or "blur" event. Or the JS code could use the technique called Ajax, where in response to such an event it looks up the nation value by making an HTTP request to the server, getting back the nation value and assigning it to the nation field. The server side code to handle the HTTP request containing the dialing prefix, and to send back the HTTP response containing the nation, could be written in Python and Django. The server side code would be considered a "RESTful Web Service", and can be written like any other Django code, using a template that is simply the value of the nation, or that value wrapped in JSON or XML or something, rather than a template that is a full HTML web page. If you find yourself writing enough such RESTful Web Services, you may want to also use the "Django Rest Framework" to do much of the work for you. Another possibility, especially if you are going to have a lot of such Ajax calls, is to use the new Django "Channels" to talk to server and get additional data like nation lookups. For more info, see: - http://google.com/search?q=django+ajax Hope this helps! --Fred
Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/ Bristle Software, Inc -- http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. On 1/17/17 11:42 AM, carlobo wrote:
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/32eea2fb-5423-9dbc-7ded-7cdea98b77a1%40bristle.com. For more options, visit https://groups.google.com/d/optout. |
- How to make a queryset into a database, starting from a tem... carlobo
- Re: How to make a queryset into a database, starting f... Fred Stluka
- Re: How to make a queryset into a database, starting f... Melvyn Sopacua