Fix race conditions on lookup fields and improve display of values
This commit is contained in:
parent
11caac5fa9
commit
df1f638c8d
6 changed files with 62 additions and 17 deletions
|
@ -71,6 +71,7 @@ class SPR(models.Model):
|
||||||
return 'no_spr'
|
return 'no_spr'
|
||||||
|
|
||||||
class SPRSerializer(serializers.ModelSerializer):
|
class SPRSerializer(serializers.ModelSerializer):
|
||||||
|
display = serializers.CharField(source='__str__', read_only=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SPR
|
model = SPR
|
||||||
fields = (
|
fields = (
|
||||||
|
@ -78,7 +79,8 @@ class SPRSerializer(serializers.ModelSerializer):
|
||||||
'name',
|
'name',
|
||||||
'code',
|
'code',
|
||||||
'country',
|
'country',
|
||||||
'slug'
|
'slug',
|
||||||
|
'display'
|
||||||
)
|
)
|
||||||
|
|
||||||
class City(models.Model):
|
class City(models.Model):
|
||||||
|
@ -102,6 +104,7 @@ class City(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class CitySerializer(serializers.ModelSerializer):
|
class CitySerializer(serializers.ModelSerializer):
|
||||||
|
display = serializers.CharField(source='__str__', read_only=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = City
|
model = City
|
||||||
fields = (
|
fields = (
|
||||||
|
@ -109,6 +112,7 @@ class CitySerializer(serializers.ModelSerializer):
|
||||||
'name',
|
'name',
|
||||||
'spr',
|
'spr',
|
||||||
'tz',
|
'tz',
|
||||||
'slug'
|
'slug',
|
||||||
|
'display'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -15,18 +15,22 @@
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
{% with event_form.fields.place.widget as widget %}
|
$("#place_search").keyup(function() {
|
||||||
$("#{{ widget.name }}_search").keyup(function() {
|
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
$.getJSON("{{ widget.source }}?q="+searchText, function(data) {
|
$.getJSON("/api/places/?q="+searchText, function(data) {
|
||||||
var selectField = $("#{{ widget.name }}_select");
|
var searchField = $("#place_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
|
var selectField = $("#place_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
selectField.append('<option value="'+ this.{{ widget.key }} +'">'+ this.name+' '+this.city + '</option>')
|
selectField.append('<option value="'+ this.id +'">'+ this.name+' '+this.city + '</option>')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
{% endwith %}
|
|
||||||
|
|
||||||
$.datepicker.setDefaults({
|
$.datepicker.setDefaults({
|
||||||
showOn: 'focus',
|
showOn: 'focus',
|
||||||
|
|
|
@ -18,10 +18,15 @@ $(document).ready(function(){
|
||||||
$("#city_search").keyup(function() {
|
$("#city_search").keyup(function() {
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
$.getJSON("/api/cities/?q="+searchText, function(data) {
|
$.getJSON("/api/cities/?q="+searchText, function(data) {
|
||||||
|
var searchField = $("#city_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#city_select");
|
var selectField = $("#city_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
selectField.append('<option value="'+ this.id +'">'+ this.name+ '</option>')
|
selectField.append('<option value="'+ this.id +'">'+ this.display+ '</option>')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,11 @@ $(document).ready(function(){
|
||||||
$("#country_search").keyup(function() {
|
$("#country_search").keyup(function() {
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
$.getJSON("/api/countries/?q="+searchText, function(data) {
|
$.getJSON("/api/countries/?q="+searchText, function(data) {
|
||||||
|
var searchField = $("#country_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#country_select");
|
var selectField = $("#country_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
@ -27,6 +32,11 @@ $(document).ready(function(){
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
var country_id = $("#country_select")[0].selectedOptions[0].value;
|
var country_id = $("#country_select")[0].selectedOptions[0].value;
|
||||||
$.getJSON("/api/spr/?q="+searchText+"&country="+country_id, function(data) {
|
$.getJSON("/api/spr/?q="+searchText+"&country="+country_id, function(data) {
|
||||||
|
var searchField = $("#spr_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#spr_select");
|
var selectField = $("#spr_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
@ -38,6 +48,11 @@ $(document).ready(function(){
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
var spr_id = $("#spr_select")[0].selectedOptions[0].value;
|
var spr_id = $("#spr_select")[0].selectedOptions[0].value;
|
||||||
$.getJSON("/api/cities/?q="+searchText+"&spr="+spr_id, function(data) {
|
$.getJSON("/api/cities/?q="+searchText+"&spr="+spr_id, function(data) {
|
||||||
|
var searchField = $("#city_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#city_select");
|
var selectField = $("#city_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
@ -45,7 +60,6 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});</script>
|
||||||
</script>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -15,18 +15,21 @@
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
{% with event_form.fields.place.widget as widget %}
|
$("#place_search").keyup(function() {
|
||||||
$("#{{ widget.name }}_search").keyup(function() {
|
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
$.getJSON("{{ widget.source }}?q="+searchText, function(data) {
|
$.getJSON("/api/places/?q="+searchText, function(data, status) {
|
||||||
var selectField = $("#{{ widget.name }}_select");
|
var searchField = $("#place_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
|
var selectField = $("#place_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
selectField.append('<option value="'+ this.{{ widget.key }} +'">'+ this.name+' '+this.city + '</option>')
|
selectField.append('<option value="'+ this.id +'">'+ this.name+' '+this.city + '</option>')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
{% endwith %}
|
|
||||||
|
|
||||||
$.datepicker.setDefaults({
|
$.datepicker.setDefaults({
|
||||||
showOn: 'focus',
|
showOn: 'focus',
|
||||||
|
|
|
@ -16,6 +16,11 @@ $(document).ready(function(){
|
||||||
$("#country_search").keyup(function() {
|
$("#country_search").keyup(function() {
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
$.getJSON("/api/countries/?q="+searchText, function(data) {
|
$.getJSON("/api/countries/?q="+searchText, function(data) {
|
||||||
|
var searchField = $("#country_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#country_select");
|
var selectField = $("#country_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
@ -27,6 +32,11 @@ $(document).ready(function(){
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
var country_id = $("#country_select")[0].selectedOptions[0].value;
|
var country_id = $("#country_select")[0].selectedOptions[0].value;
|
||||||
$.getJSON("/api/spr/?q="+searchText+"&country="+country_id, function(data) {
|
$.getJSON("/api/spr/?q="+searchText+"&country="+country_id, function(data) {
|
||||||
|
var searchField = $("#spr_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#spr_select");
|
var selectField = $("#spr_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
@ -38,6 +48,11 @@ $(document).ready(function(){
|
||||||
var searchText = this.value;
|
var searchText = this.value;
|
||||||
var spr_id = $("#spr_select")[0].selectedOptions[0].value;
|
var spr_id = $("#spr_select")[0].selectedOptions[0].value;
|
||||||
$.getJSON("/api/cities/?q="+searchText+"&spr="+spr_id, function(data) {
|
$.getJSON("/api/cities/?q="+searchText+"&spr="+spr_id, function(data) {
|
||||||
|
var searchField = $("#city_search")[0];
|
||||||
|
var q = this.url.match(/q=([^&]+)/)[1]
|
||||||
|
var c = searchField.value
|
||||||
|
if (c != q) return;
|
||||||
|
|
||||||
var selectField = $("#city_select");
|
var selectField = $("#city_select");
|
||||||
selectField.empty();
|
selectField.empty();
|
||||||
$.each(data, function(){
|
$.each(data, function(){
|
||||||
|
|
Loading…
Reference in a new issue