[1.7.x] Fixed #22906 -- Added a more helpful repr to migrations' ModelState.
Thanks Collin Anderson for the report and original patch.
Backport of 2572c07cc6
from master
This commit is contained in:
parent
8fbd9b0b1c
commit
a1ddfe4401
|
@ -300,6 +300,9 @@ class ModelState(object):
|
||||||
return field
|
return field
|
||||||
raise ValueError("No field called %s on model %s" % (name, self.name))
|
raise ValueError("No field called %s on model %s" % (name, self.name))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<ModelState: '%s.%s'>" % (self.app_label, self.name)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (
|
return (
|
||||||
(self.app_label == other.app_label) and
|
(self.app_label == other.app_label) and
|
||||||
|
|
|
@ -420,3 +420,13 @@ class ModelStateTests(TestCase):
|
||||||
state = ModelState('app', 'Model', [('name', field)])
|
state = ModelState('app', 'Model', [('name', field)])
|
||||||
Model = state.render(apps)
|
Model = state.render(apps)
|
||||||
self.assertNotEqual(Model._meta.get_field('name'), field)
|
self.assertNotEqual(Model._meta.get_field('name'), field)
|
||||||
|
|
||||||
|
def test_repr(self):
|
||||||
|
field = models.CharField(max_length=1)
|
||||||
|
state = ModelState('app', 'Model', [('name', field)], bases=['app.A', 'app.B', 'app.C'])
|
||||||
|
self.assertEqual(repr(state), "<ModelState: 'app.Model'>")
|
||||||
|
|
||||||
|
project_state = ProjectState()
|
||||||
|
project_state.add_model_state(state)
|
||||||
|
with self.assertRaisesMessage(InvalidBasesError, "Cannot resolve bases for [<ModelState: 'app.Model'>]"):
|
||||||
|
project_state.render()
|
||||||
|
|
Loading…
Reference in New Issue