A quick note on recursive models – when creating a relation such as a category nest, it’s really easy to create a scenario where loaddata fails to load. What happens is that the dependency instance may get listed after the child in the dumpdata output. With certain database engines that relation must be resolved at point of mention during import. The solution seems obvious when you hear it, but may not seem so obvious when you hit it – in the model do not specify the order as anything other than “created” or “id” and create the recursion in drilldown order. Given these two conventions, data should be able to load regardless of the database. I ran into trouble using a title order to get an alpha sort in the admin and just didn’t consider that the meta order would be represented in the dump as well, though upon further thought it makes perfect sense.
class Category(KeenerElementsBase):
"""
recursive category nest model
"""
...
parent = models.ForeignKey('self', blank=True, null=True)
class Meta:
...
ordering = ('id',)
“”"
Category model.
A nesting container, can be recursive using parent
“”"
weight = models.IntegerField(‘weight’,default=50)
parent = models.ForeignKey(’self’, blank=True, null=True)
class Meta:
verbose_name = ‘category’
verbose_name_plural = ‘categories’
# dump/loaddata recursive relationship needs to be maintained
ordering = (‘id’,)
