搜索多对多的关系

时间:2015-06-03 19:51:57

标签: django django-models many-to-many manytomanyfield

鉴于贡献者,我试图找到贡献者所属的注册。我无法弄清楚如何遍历M2M-我需要知道哪些注册包含了他们的“conrtibutor”中的贡献者。场...?

var store = [];
document.getElementById('file').onchange = function(){
    var file = this.files[0];
    var reader = new FileReader();

    // Define the body of reader function
    reader.onload = function(progressEvent){

        // By lines
        var lines = this.result.split('\n');
        for(var line = 0; line < lines.length; line++){

            // Store it in an array
            store.push(lines[line]);
        }
        // Correctly reads the final length of the store variable.
        console.log(store.length);
    };

    reader.readAsText(file);
};

2 个答案:

答案 0 :(得分:0)

我想你只需要这个:

# assuming you have a contributor
Registration.objects.filter(contributor=your_contributor_object)

答案 1 :(得分:0)

使用related_name进行反向访问。

def which_registration(self):
    #if you dont define related_name you should use
    #return self.registration_set.all()
    return self.registrations.all()
相关问题