本文介绍了GAE:模型失去父级>子关系的跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在google app引擎数据存储中遇到了一个非常奇怪的Entity关系问题。我在一个Python / GAE webapp(学习练习),完整的代码可以在。

I'm having what seems like a very strange problem with an Entity relationship in the google app engine data store. I'm work on a Python/GAE webapp (learning exercise), the full code to which can be found on sourceforge.


  • 我有2个型号:

    • - 搜索字词和(间接)照片列表

    • - 有关照片的信息,


    • 我有一个获取过程,可以创建图库并向其中添加照片

    • 我有一个从数据存储区读取图库的页面,并使用该图库实例的.photos属性来获取其中的照片列表。

    • I have 2 models:
      • Gallery - a search term and (indirectly) a list of photos
      • Photo - information about a photo, plus the gallery it belongs to (collection_index='photos')

      现在这是奇怪的部分来的地方... 如果我更改一个文件(我测试过的任何文件),或者只是更新文件的时间戳例如,如果我尝试加载:

      Now this is where the weird part comes in... If I change a file (any file I've tested on) or even just update the timestamp of the file (ie, so it gets reloaded)... the ".photos" attribute of galleries starts failing. For example, if I try to load the page for the "flowers" gallery:

       c $  $  >类,应用程序引擎重新加载代码...因为它的定义被正在修改的文件无效

    • 因为它不知道它需要照片类,它不会加载该文件,因此 Gallery 类的新实例没有应该

    My first solution was to add a dependency on the Photo file in the Gallery file.

    from app.models.photo import Photo
    

    这样的问题是在两个文件之间创建一个循环依赖(因为照片已经需要知道图库以获得它们的列表)。虽然它工作,我被告知Python有问题与循环依赖,这可能不是一件好事;

    The problem with this is that it creates a circular dependency between the two files (since Photo already needs to know about Gallery in order to have a list of them). While it worked, I was told that Python has "problems" with circular dependencies, and it's probably not a good thing to do; it may come back to bite me later.

    我解决的解决方案是将__init.py 文件所讨论的包包括两个文件的依赖关系。因此,任何时候只需要其中一个文件即可加载。

    The solution I wound up going with was to have the __init.py file for the package in question include a dependency for both files. As such, any time either one of the files is needed, both will be loaded.

    这篇关于GAE:模型失去父级>子关系的跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:02