add natural key support to ResponseType
Have the option to use the more readable response type value rather than the ResponseType id integer in fixtures and dumpdata output. Prior to this change dumpdata represents response types like so: "response_types": [2] And after this change when using `dumpdata --natural-foreign`: "response_types": [["code"]]
This commit is contained in:
parent
436568a39b
commit
4e7116ca9e
1 changed files with 10 additions and 0 deletions
|
@ -30,7 +30,14 @@ JWT_ALGS = [
|
|||
]
|
||||
|
||||
|
||||
class ResponseTypeManager(models.Manager):
|
||||
def get_by_natural_key(self, value):
|
||||
return self.get(value=value)
|
||||
|
||||
|
||||
class ResponseType(models.Model):
|
||||
objects = ResponseTypeManager()
|
||||
|
||||
value = models.CharField(
|
||||
max_length=30,
|
||||
choices=RESPONSE_TYPE_CHOICES,
|
||||
|
@ -40,6 +47,9 @@ class ResponseType(models.Model):
|
|||
max_length=50,
|
||||
)
|
||||
|
||||
def natural_key(self):
|
||||
return self.value, # natural_key must return tuple
|
||||
|
||||
def __str__(self):
|
||||
return u'{0}'.format(self.description)
|
||||
|
||||
|
|
Loading…
Reference in a new issue