Skip to content

Commit

Permalink
[bugfix] Override get_temp_model_instance to add org #27
Browse files Browse the repository at this point in the history
Fixes #27
Closes #87
Closes #88
  • Loading branch information
nemesifier committed Mar 31, 2019
1 parent 91fe561 commit d3ae2ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions openwisp_controller/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ class ConfigForm(AlwaysHasChangedMixin, AbstractConfigForm):
class Meta(AbstractConfigForm.Meta):
model = Config

def get_temp_model_instance(self, **options):
config_model = self.Meta.model
instance = self.Meta.model(**options)
device_model = config_model.device.field.related_model
org = Organization.objects.get(pk=self.data['organization'])
instance.device = device_model(
name=self.data['name'],
mac_address=self.data['mac_address'],
organization=org
)
return instance


class ConfigInline(MultitenantAdminMixin, AbstractConfigInline):
model = Config
Expand Down
8 changes: 7 additions & 1 deletion openwisp_controller/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def get_default_templates(self):
""" see ``openwisp_controller.config.utils.get_default_templates_queryset`` """
queryset = super(TemplatesVpnMixin, self).get_default_templates()
assert self.device
return get_default_templates_queryset(self.device.organization_id, queryset=queryset)
return get_default_templates_queryset(self.device.organization_id,
queryset=queryset)

@classmethod
def clean_templates_org(cls, action, instance, pk_set, **kwargs):
Expand Down Expand Up @@ -98,6 +99,11 @@ class Meta(AbstractDevice.Meta):
)
abstract = False

def get_temp_config_instance(self, **options):
c = super(Device, self).get_temp_config_instance(**options)
c.device = self
return c


class Config(TemplatesVpnMixin, AbstractConfig):
"""
Expand Down

0 comments on commit d3ae2ed

Please sign in to comment.