Closed araichev closed 10 years ago
The default name for an imported feed is Imported at <now>
, which helps make it unique with no effort. If you run ./manage.py importgtfs --help
, you'll see the full options for importgtfs, which includes a '--name' option. I recommend a name like ./manage.py importgtfs sydney.zip --name=sydney_jun_2013.1
, so that it is human friendly but also unique and allows you to add multiple feeds as you fix things.
You can get to the routes two ways:
sydney_feed = Feed.objects.get(name='sydney_jun_2013.1')
sydney_routes1 = sydney_feed.route_set.all()
sydney_routes2 = Routes.objects.in_feed(sydney_feed)
sydney_routes1
and sydney_routes2
are equivalent. The first way uses the standard Django methods for following foreign keys, so it should be easy for experienced Django users to understand what you're doing. The advantage to in_feed
is that all the GTFS objects (or 'managers', in the Django parlance) have the in_feed
method, and it works even if the relation from the feed to the objects goes through a couple of layers. It is mostly used for exporting (see /multigtfs/models/feed.py, export_gtfs()), but you might want to use it in your app code as well. Use whichever one makes the code easier to read.
Thanks heaps for the explanation, John. Can you add it to the docs?
Yes, docs would be a good idea. I'll leave this ticket open until it's part of the docs.
Adding issue #26 for documentation needs.
How do i import and use multiple feeds, say for two different cities, in one database? I can't figure this out from the current app documentation.
For example, i have GTFS files for Auckland and Sydney. If i import Auckland's via
python manage.py importgtfs auckland.zip
and then import Sydney's via the analogous command, does the Sydney import overwrite the Auckland one? Is the Auckland one saved as feed 1 and Sydney as feed 2? In the latter case, how would i get all the routes for the two feeds separately within an app or the shell?sydney_routes = Feed.objects.get(feed_id='2').Route.objects.all()
?Personally, i would like the following functionality. For imports from the command line:
python manage.py importgtfs my_gtfs_zipfile_or_directory my_name_for_this_feed
, wheremy_name_for_this_feed
defaults tofeed_my_gtfs_zipfile_or_directory
. For use within an app or the shell, i would like to be able to dofeed = Feed.objects.get(feed_name)
and things likefeed_routes = feed.Route.objects.all()
.What do you all think?