Skip to content

Commit

Permalink
Added deconstruct
Browse files Browse the repository at this point in the history
  • Loading branch information
nafeesanwar committed Apr 30, 2021
1 parent a56d07c commit 9deb39d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions model_utils/fields.py
Expand Up @@ -349,3 +349,8 @@ def get_default(self):
# generate a token of length x1.33 approx. trim up to max length
token = secrets.token_urlsafe(self.max_length)[:self.max_length]
return token

def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
kwargs['factory'] = self._factory
return name, path, args, kwargs
9 changes: 9 additions & 0 deletions tests/test_fields/test_urlsafe_token_field.py
Expand Up @@ -53,3 +53,12 @@ def test_get_default_with_factory(self):
def test_no_default_param(self):
field = UrlsafeTokenField(default='DEFAULT')
self.assertIs(field.default, NOT_PROVIDED)

def test_deconstruct(self):
def test_factory():
pass
instance = UrlsafeTokenField(factory=test_factory)
name, path, args, kwargs = instance.deconstruct()
new_instance = UrlsafeTokenField(*args, **kwargs)
self.assertIs(instance._factory, new_instance._factory)
self.assertIs(test_factory, new_instance._factory)

0 comments on commit 9deb39d

Please sign in to comment.