소스 검색

# feat:科研工作模块搭建完成

yang yi 1 주 전
부모
커밋
0f8eff2a17
2개의 변경된 파일56개의 추가작업 그리고 5개의 파일을 삭제
  1. 44 4
      pythonweb/scientificApp/templates/scientific.html
  2. 12 1
      pythonweb/scientificApp/views.py

+ 44 - 4
pythonweb/scientificApp/templates/scientific.html

@@ -1,11 +1,51 @@
 {% extends "base.html" %}
 
-{% block title %}
-科研工作
-{% endblock %}
+{% block title %}{{ title }}{% endblock %}
 
 {% block content %}
 <div class="container">
-    <h1>科研工作</h1>
+    <div class="row">
+        <div class="col-md-3">
+            <div class="model-title">{{ title }}</div>
+            <div class="model-list">
+                <ul class="list-group">
+                    <li class="list-group-item active" id="survey">
+                        <a href="{% url 'scientific_index' %}">教学科研</a>
+                    </li>
+                </ul>
+            </div>
+        </div>
+        <div class="col-md-9">
+            <div class="model-details-title">{{ title }}</div>
+            <div class="row">
+                {% for article in list %}
+                <div class="col-md-4">
+                    <div class="thumbnail">
+                        {% if article.cover %}
+                        <img src="{{ article.cover }}" alt="{{ article.title }}" class="img-responsive" style="height:200px;object-fit:cover;">
+                        {% endif %}
+                        <div class="caption">
+                            <h4 style="text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">{{ article.title }}</h4>
+                            <p style="text-align:center;color:#999;">{{ article.created_at|date:"Y-m-d" }}</p>
+                        </div>
+                    </div>
+                </div>
+                {% endfor %}
+            </div>
+            {% if list.has_other_pages %}
+            <nav>
+                <ul class="pagination">
+                    {% if list.has_previous %}
+                    <li><a href="?page={{ list.previous_page_number }}">&laquo;上一页</a></li>
+                    {% endif %}
+                    <li><span>第 {{ list.number }} / {{ list.paginator.num_pages }} 页</span></li>
+                    {% if list.has_next %}
+                    <li><a href="?page={{ list.next_page_number }}">下一页&raquo;</a></li>
+                    {% endif %}
+                </ul>
+            </nav>
+            {% endif %}
+        </div>
+    </div>
 </div>
 {% endblock %}

+ 12 - 1
pythonweb/scientificApp/views.py

@@ -1,5 +1,16 @@
 from django.shortcuts import render
+from django.core.paginator import Paginator
+from common.models import Article
 
 
 def index(request):
-    return render(request, 'scientific.html')
+    articles = Article.objects.filter(category='scientific').all()
+    paginator = Paginator(articles, 12)
+    page_number = request.GET.get('page')
+    page_obj = paginator.get_page(page_number)
+    context = {
+        'title': '教学科研',
+        'list': page_obj,
+        'active_menu': 'scientific',
+    }
+    return render(request, 'scientific.html', context)