如何从管理站点在站点上显示文本?

时间:2019-07-18 10:33:20

标签: html django

在管理站点上,我创建ConclusionNameRetrospectiveField。我需要字段baseTextcomments出现在网站上的Application 2 'Retrospective'字下

结论(应用程序) models.py

class ConclusionName(models.Model):
    name = models.CharField(max_length=250)

    def __unicode__(self):
        return self.name

class RetrospectiveField(models.Model):
     user = models.ForeignKey(User)
     conclusionName = models.ForeignKey(ConclusionName)
     baseText = models.TextField(max_length=255)
     comments = models.TextField(max_length=255)
     project = models.ForeignKey(Project)

forms.py

class RetrospectiveFieldForm(forms.Form):
    project = forms.ModelChoiceField(queryset=Project.objects.all(), label=u'Project')
    conclusionName = forms.ModelChoiceField(queryset=ConclusionName.objects.all(), label=u'ConclusionName')
    baseText = forms.TextField(max_length=255, label=u'BaseText')
    comments = forms.TextField(max_length=255, label=u'Comments')

    class Meta:
        model = RetrospectiveField
        fields = ('project', 'conclusionName', 'baseText', 'comments',)

views.py

def add_form_retrospective_field(request):
    if request.method == 'POST':
        form = RetrospectiveFieldForm(request.POST)
        if form.is_valid():
            retro = RetrospectiveField()
            retro.user = User.objects.get(username=request.user)
            retro.project = form.cleaned_data.get('project')
            retro.conclusionName = form.cleaned_data.get('conclusionName')
            retro.baseText = form.cleaned_data.get('baseText')
            retro.comments = form.cleaned_data.get('comments')
            retro.save()
            return redirect('/')
    else:
        form = RetrospectiveForm()
    return render(request, 'completeness/forms_retrospective_field.html', {'form': form})

def showRetrospectiveField(request, slug):
    projects = Project.objects.filter(id=slug)
    retrospectiveFields = RetrospectiveField.objects.get(project=projects)
    return render(request, 'completeness/view_retrospectiveField.html', {'retrospectiveFields': retrospectiveFields})

conclusion / example.html

{% extends 'completeness/base.html' %}
{% load staticfiles %}
{% load i18n %}
{% block title %}{% trans 'Network' %}{% endblock %}
{% block head %}
    <meta charset="UTF-8">
    <title>Conclusion</title>
    <script data-require="jquery@*" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
{% block js %}
{{ form.media }}
{% endblock %}
{% endblock head %}
{% block content %}
<div class="parent">
    <div class="block">    
        <h3>Application 2 "Retrospective"</h3>
    {% for retro in retrospectiveField %}
    <p>{{ retro.baseText }}</p>
    <p>{{ retro.comments }}</p>
    {% endfor %}                
    </div>
</div>
{% endblock content %}

1 个答案:

答案 0 :(得分:0)

您正在retrospectiveFields视图中返回showRetrospectiveField,但是您在retrospectiveField的for循环中使用了conclusion/example.html