Last active
January 18, 2018 02:47
-
-
Save nck2/0cb9a3ac864b6dbb62ff1506b7fb4a1f to your computer and use it in GitHub Desktop.
사전으로 넘긴 쿼리셋에 대하여 실행시 중복되는 템플릿 구문 해결방법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py########################## | |
class SageSource(models.Model): | |
title = models.CharField(max_length=200, verbose_name = "제목") | |
code = models.TextField(blank=False, verbose_name="소스코드") | |
cat= (("1","대수"),('2','해석')) | |
category = models.CharField(verbose_name="분야", max_length=20, default="대수",choices=cat) | |
def __str__(self): | |
return self.title | |
class Meta: | |
ordering=['pk'] | |
# views.py########################## | |
class ArchiveLV(ListView): | |
model = SageSource | |
template_name = 'sage/archive.html' | |
def get_context_data(self, **kwargs): | |
context = super(ArchiveLV, self).get_context_data(**kwargs) | |
context['대수']= SageSource.objects.filter(category='대수') | |
context['해석']= SageSource.objects.filter(category='해석') | |
return context | |
# archive.html########################## | |
<h3>대수</h3> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>제목</th> | |
<th>코드</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for i in 대수%} | |
<tr> | |
<td>{{i.title}}</td> | |
<td>{{i.code|linebreaks}}</td> | |
</tr> | |
{% endfor %} | |
</tbody> | |
</table> | |
#####여기부터 중복되는 부분,, 해결필요!!####### | |
<h3>해석</h3> | |
<table class="table"> | |
<thead> | |
<tr> | |
<th>제목</th> | |
<th>코드</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for i in 해석%} | |
<tr> | |
<td>{{i.title}}</td> | |
<td>{{i.code|linebreaks}}</td> | |
</tr> | |
{% endfor %} | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment