diff --git a/django_loci/base/admin.py b/django_loci/base/admin.py index c893c6d..94c0445 100644 --- a/django_loci/base/admin.py +++ b/django_loci/base/admin.py @@ -220,9 +220,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # set initial values for custom fields initial = {} - obj = self.instance - location = obj.location - floorplan = obj.floorplan + location = self._get_initial_location() + floorplan = self._get_initial_floorplan() if location: initial.update( { @@ -249,6 +248,12 @@ def __init__(self, *args, **kwargs): ] self.initial.update(initial) + def _get_initial_location(self): + return self.instance.location + + def _get_initial_floorplan(self): + return self.instance.floorplan + @cached_property def floorplan_model(self): return self.Meta.model.floorplan.field.remote_field.model