From 45bd70229c7f230ed827e0ac8f6f63dff972419b Mon Sep 17 00:00:00 2001
From: David Barnes <barnesdavidj@gmail.com>
Date: Thu, 8 Sep 2022 17:41:16 -0400
Subject: [PATCH] Alter class definition dump to remove m2m relation since
 python's get_memebers method calls some logic in Django that can't handle
 getting the members when the object (class definition in this case) does not
 have a id / pk set.

---
 django_dump_die/views/example_helpers.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/django_dump_die/views/example_helpers.py b/django_dump_die/views/example_helpers.py
index 777c68b..e007bf1 100644
--- a/django_dump_die/views/example_helpers.py
+++ b/django_dump_die/views/example_helpers.py
@@ -727,7 +727,16 @@ def dump_model_types():
     # Call dump on all generated variables.
     dump('')
     dump('Model and ModelForm class examples:')
-    dump(SampleDjangoModel)
+    # TODO: See if there is a better way to "fix" this.
+    # Need to remove the Many-To-Many relationship when dumping the class
+    # definition (non-instance) because python's get_members can't handle a
+    # m2m when the "object" does not have an id. Which it can't due to it being
+    # a class definition and not an instance. Problem is solved when an instance
+    # is created. See below dump of instance.
+    SampleDjangoModelNoManyRelation = copy.deepcopy(SampleDjangoModel)
+    delattr(SampleDjangoModelNoManyRelation, 'sample_many')
+    dump(SampleDjangoModelNoManyRelation)
+
     dump(SampleModelForm)
 
     dump('')
-- 
GitLab