Browse Source

Fix non existant object

Denis K 8 years ago
parent
commit
cf51f66cd6
1 changed files with 6 additions and 3 deletions
  1. 6 3
      jet/templatetags/jet_tags.py

+ 6 - 3
jet/templatetags/jet_tags.py

@@ -160,9 +160,12 @@ def jet_select2_lookups(field):
                 field.field.choices = choices
             elif hasattr(field, 'field') and isinstance(field.field, ModelChoiceField):
                 if initial_value:
-                    initial_object = model.objects.get(pk=initial_value)
-                    attrs['data-object-id'] = initial_value
-                    choices.append((initial_object.pk, get_model_instance_label(initial_object)))
+                    try:
+                        initial_object = model.objects.get(pk=initial_value)
+                        attrs['data-object-id'] = initial_value
+                        choices.append((initial_object.pk, get_model_instance_label(initial_object)))
+                    except model.DoesNotExist:
+                        pass
 
                 if isinstance(field.field.widget, RelatedFieldWidgetWrapper):
                     field.field.widget.widget = Select(attrs)