I\'ve seen a few similar questions to this on SO, but none seem to answer my particular problem. I\'m new to Django and was guiding myself by the instructions at this page t
You need to
natural_key
method in your modelsget_by_natural_key
methodobjects=GraphManager()
)After playing with your code, I made it work:
class GraphTypeManager(models.Manager):
def get_by_natural_key(self, type):
return self.get(type=type)
class GraphType(models.Model):
type = models.CharField(max_length=100, unique=True)
objects = GraphTypeManager()
def natural_key(self):
return (self.type,) # must return a tuple
class GraphManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
class Graph(models.Model):
name = models.CharField(max_length=200, unique=True)
type = models.ForeignKey(GraphType)
objects = GraphManager()
Dumping the data:
$ bin/django dumpdata index --indent=4 --natural > project/apps/fixtures_dev/initial_data.json
[
{
"pk": 1,
"model": "index.graphtype",
"fields": {
"type": "asotuh"
}
},
{
"pk": 1,
"model": "index.graph",
"fields": {
"type": [
"asotuh"
],
"name": "saoneuht"
}
}
]
bin/django loaddata project/apps/fixtures_dev/initial_data.json
Installed 2 object(s) from 1 fixture(s)