Repository: openwisp/openwisp-network-topology (language: python)

Issue:
[enhancement] Organization field in Snapshot model is redundant 
A snapshot cannot have organization different from the topology. We can safely remove the organization field. 



**Note for new contributors**
The organization field is added using `openwisp_users.mixins.OrgMixin`
[enhancement] Organization field in Snapshot model is redundant 
A snapshot cannot have organization different from the topology. We can safely remove the organization field. 



**Note for new contributors**
The organization field is added using `openwisp_users.mixins.OrgMixin`


Discussion / hints:

Fix patch:
diff --git a/openwisp_network_topology/base/snapshot.py b/openwisp_network_topology/base/snapshot.py
index 7cafd67a..ed5ae879 100644
--- a/openwisp_network_topology/base/snapshot.py
+++ b/openwisp_network_topology/base/snapshot.py
@@ -2,11 +2,10 @@
 from django.db import models
 from django.utils.translation import gettext_lazy as _
 
-from openwisp_users.mixins import OrgMixin
 from openwisp_utils.base import TimeStampedEditableModel
 
 
-class AbstractSnapshot(OrgMixin, TimeStampedEditableModel):
+class AbstractSnapshot(TimeStampedEditableModel):
     """
     NetJSON NetworkGraph Snapshot implementation
     """
diff --git a/openwisp_network_topology/base/topology.py b/openwisp_network_topology/base/topology.py
index cc6d8cb4..83a071a7 100644
--- a/openwisp_network_topology/base/topology.py
+++ b/openwisp_network_topology/base/topology.py
@@ -313,7 +313,7 @@ def save_snapshot(self, **kwargs):
         """
         Snapshot = self.snapshot_model
         date = datetime.now().date()
-        options = dict(organization=self.organization, topology=self, date=date)
+        options = dict(topology=self, date=date)
         options.update(kwargs)
         try:
             s = Snapshot.objects.get(**options)
diff --git a/openwisp_network_topology/migrations/0014_remove_snapshot_organization.py b/openwisp_network_topology/migrations/0014_remove_snapshot_organization.py
new file mode 100644
index 00000000..b97586f6
--- /dev/null
+++ b/openwisp_network_topology/migrations/0014_remove_snapshot_organization.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.1.14 on 2022-02-02 07:12
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('topology', '0013_add_user_defined_properties_field'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='snapshot',
+            name='organization',
+        ),
+    ]


Test patch:
diff --git a/tests/openwisp2/sample_network_topology/migrations/0001_initial.py b/tests/openwisp2/sample_network_topology/migrations/0001_initial.py
index 0f9e19e2..fccd5199 100644
--- a/tests/openwisp2/sample_network_topology/migrations/0001_initial.py
+++ b/tests/openwisp2/sample_network_topology/migrations/0001_initial.py
@@ -195,14 +195,6 @@ class Migration(migrations.Migration):
                 ('data', models.TextField()),
                 ('date', models.DateField(auto_now=True)),
                 ('details', models.CharField(blank=True, max_length=64, null=True)),
-                (
-                    'organization',
-                    models.ForeignKey(
-                        on_delete=django.db.models.deletion.CASCADE,
-                        to=get_model_name('openwisp_users', 'Organization'),
-                        verbose_name='organization',
-                    ),
-                ),
                 (
                     'topology',
                     models.ForeignKey(