﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21830	dumpdata: option to fetch related objects	stanislas.guerra@…	nobody	"Hi,

Just started to [https://github.com/Starou/django/compare/dumpdata-related?expand=1 write a patch] that add a ''--related'' option to the dumpdata command where you can specify the related objects you want to fetch aside the main one using ''--pks''.

for example:


{{{
class Article(models.Model):
    headline = models.CharField(max_length=100, default='Default headline')
    pub_date = models.DateTimeField()
    tag = models.ForeignKey(""Tag"")


class Tag(models.Model):
    name = models.CharField(max_length=100)



class Blog(models.Model):
    name = models.CharField(max_length=100)
    featured = models.ForeignKey(Article, related_name='fixtures_featured_set')
    articles = models.ManyToManyField(Article, blank=True,
                                      related_name='fixtures_articles_set')

}}}

Allows you to dump several blogs, the articles and the tag on the articles.


{{{
python manage.py dumpdata myapp.Blog --pks=2,3 --related=articles.tag,articles,featured
}}}

This is very basic at the moment and there are some limitations:

* If you use the ''--natural'' switch, you have to be careful in the related order because objects are not sorted ;
* Objects can appear several times (in the previous example, if the ''featured'' article is also in the ''articles'' relation it will be present 2 times in the dump).


"	New feature	closed	Core (Serialization)	dev	Normal	duplicate	dumpdata		Unreviewed	1	0	0	0	0	0
