Skip to content
This repository has been archived by the owner on Jul 9, 2020. It is now read-only.

Commit

Permalink
[qa] Moved sortedm2m__str__ to base models
Browse files Browse the repository at this point in the history
References #29
  • Loading branch information
nemesifier committed Apr 21, 2017
1 parent e399368 commit 47b7009
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 12 additions & 0 deletions django_netjsonconfig/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,15 @@ def get_context(self):

class Meta:
abstract = True


def sortedm2m__str__(self):
"""
Improves string representation of m2m relationship objects
TODO
----
this method can be removed if the following pull request
gets merged: https://github.com/gregmuellegger/django-sortedm2m/pull/101
"""
return _('Relationship with {0}').format(self.template.name)
9 changes: 1 addition & 8 deletions django_netjsonconfig/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base.config import AbstractConfig, TemplatesVpnMixin
from .base.config import AbstractConfig, TemplatesVpnMixin, sortedm2m__str__
from .base.template import AbstractTemplate
from .base.vpn import AbstractVpn, AbstractVpnClient

Expand All @@ -11,13 +11,6 @@ class Meta(AbstractConfig.Meta):
abstract = False


def sortedm2m__str__(self):
"""
Improves string representation of m2m relationship objects
"""
return self.template.name


Config.templates.through.__str__ = sortedm2m__str__


Expand Down
7 changes: 7 additions & 0 deletions django_netjsonconfig/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,10 @@ def test_vpn_context_no_cert(self):
self.assertNotIn(key_contents_key, context)
self.assertIn(ca_path_key, context)
self.assertIn(ca_contents_key, context)

def test_m2m_str_conversion(self):
t = self._create_template()
c = self._create_config(name='test-m2m-str-repr')
c.templates.add(t)
c.save()
self.assertIn('Relationship with', str(c.templates.through.objects.first()))

0 comments on commit 47b7009

Please sign in to comment.