在Django模板中查看Neo4j的节点和关系

时间:2018-10-25 09:39:18

标签: python django neo4j neomodel

我正在尝试通过Neomodel从Django模板中的Neo4j数据库中检索数据。

以下是我在Neo4j中拥有的信息的一个示例:

Neo4j sample for SKINCLAS CodeList

这是我的模型。py:

from django.db import models
from django.utils import timezone
from neomodel import (config, install_all_labels, StructuredNode, StructuredRel, StringProperty, IntegerProperty, UniqueIdProperty, Relationship, RelationshipTo, RelationshipFrom, DateProperty)

config.DATABASE_URL = 'bolt://neo4j:mypassword@localhost:7687'

class CodeListRelation(StructuredRel):
    From = IntegerProperty()
    To = IntegerProperty()

class CodeList(StructuredNode):
    OID = StringProperty(unique_index=True)
    Name = StringProperty()
    EnumeratedItems = RelationshipTo('EnumeratedItem', 'Has_EnumeratedItem', model = CodeListRelation)

class EnumeratedItem(StructuredNode):
    CodedValue = StringProperty()
    nciodm_ExtCodeID = StringProperty()
    CodeLists = RelationshipFrom(CodeList, 'Has_EnumeratedItem', model = CodeListRelation)

然后在view.py文件中,我具有以下内容:

from django.shortcuts import render

def get_codelists(request):
    local_codelist = CodeList.nodes.order_by('nciodm_CDISCSubmissionValue')
    context = {'codelists': local_codelist}
    return render(request, 'lgcdfn/codelists.html', context)

这是我的html文件(在这里称为codelist.html):

{% for codelist in codelists %}
<br><a id="{{ codelist.Name }}"></a>
<div>
    <table>
        <caption><span>{{ codelist.Name }}</span></caption>
        <tr class="header">
            <th scope="col">Ext Code ID</th>
            <th scope="col">Coded Value</th>
            <th scope="col">Validity dates</th>
        </tr>
        {% for enumerateditem in codelist.EnumeratedItems %}
        <tr>
            <td>{{ enumerateditem.nciodm_ExtCodeID }}</td>
            <td>{{ enumerateditem.CodedValue }}</td>
            <td>From: {{ enumerateditem.CodeLists.From }}<br/>To: {{ enumerateditem.CodeLists.To }}</td>
        </tr>
        {% endfor %}
    </table>
</div>
{% endfor %}

因此,使用以下代码,我将获得以下html页面:

Screen Copy of the result for SKINCLAS

所以我的问题是: -如何根据CodedValue排序EnumeratedItem(在这里称为enumerateditem.CodedValue)? -为什么我没有得到有效日期(在这里调用enumerateditem.CodeLists.From和enumerateditem.CodeLists.To存放在Neo4j下的关系中)?

预先感谢您的帮助。

0 个答案:

没有答案