Fixed update bug in CorpContact admin selects
The problem is that Django RelatedObjectLookups.js is triggering select changes for the initial value and we don't want to change the contact list for this initial change (unless we lose the currently selected value).
This commit is contained in:
parent
f39724f551
commit
579236986e
3 changed files with 6 additions and 4 deletions
|
|
@ -360,7 +360,7 @@ class PeriodAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
class AvailabilityAdmin(admin.ModelAdmin):
|
||||
list_display = ('corporation', 'period', 'domain')
|
||||
list_display = ('corporation', 'period', 'domain', 'contact')
|
||||
list_filter = ('period',)
|
||||
fields = (('corporation', 'period'), 'domain', 'contact', 'priority', 'comment')
|
||||
form = AvailabilityAdminForm
|
||||
|
|
@ -370,7 +370,7 @@ class AvailabilityAdmin(admin.ModelAdmin):
|
|||
kwargs["queryset"] = Corporation.objects.filter(archived=False).order_by('name')
|
||||
if db_field.name == "contact":
|
||||
kwargs["queryset"] = CorpContact.objects.filter(archived=False)
|
||||
return super(AvailabilityAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
|
||||
|
||||
class TrainingAdmin(admin.ModelAdmin):
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ django.jQuery(document).ready(function() {
|
|||
django.jQuery('#id_corporation, .field-corporation select').change(function(ev) {
|
||||
// Fill contact select
|
||||
// Either in availability admin, or in stages admin with availability inlines
|
||||
if (this.id == 'id_period') return;
|
||||
if (this.id == 'id_corporation') var sel = django.jQuery('#id_contact');
|
||||
else var sel = django.jQuery(this).closest('fieldset').find('.field-contact select');
|
||||
sel.html('<option value="">-------</option>');
|
||||
var id_corp = django.jQuery("option:selected", this).val();
|
||||
django.jQuery.getJSON('/corporation/' + id_corp + '/contacts/', function(data) {
|
||||
if (data.length && data[0].corporation_id == id_corp) return
|
||||
sel.html('<option value="">-------</option>');
|
||||
django.jQuery.each(data, function(key, contact) {
|
||||
var item = contact.first_name + ' ' + contact.last_name;
|
||||
if (contact.role.length) item += ' (' + contact.role + ')';
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ class TrainingsByPeriodView(ListView):
|
|||
|
||||
class CorpContactJSONView(ListView):
|
||||
""" Return all contacts from a given corporation """
|
||||
return_fields = ['id', 'first_name', 'last_name', 'role', 'is_main']
|
||||
return_fields = ['id', 'first_name', 'last_name', 'role', 'is_main', 'corporation_id']
|
||||
|
||||
def get_queryset(self):
|
||||
return CorpContact.objects.filter(corporation__pk=self.kwargs['pk'], archived=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue