From cc5c7d03d951f4dacd8e1b4c2d784dcc68d01328 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 7 Jan 2025 18:47:05 +0530 Subject: [PATCH] [refactor] Added helper methods in AbstractObjectLocationForm --- django_loci/base/admin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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