Support for q and foreign key

@maennel I have added support for 2 things we had forgotten:
 - Q objects for the filtering
 - ForeignKey when building list of visited tables