다른 모델의 쿼리 세트 두 개를 목록에 결합하고 페이지 매김을 사용하여 단일 목록으로 표시했습니다.Django 다중 쿼리 세트를 페이지 매기기로 결합
문제는 목록의 개체가 만들어진 모델에 따라 페이지 매김에 표시된다는 것입니다. 새로운 객체 모델에서 생성 될 때
어떻게 그렇게 목록을 수정할 수 있습니다. 최근 생성 된 객체가 다른 모델에서 생성 되었더라도 최근에 생성 된 객체 뒤에 표시됩니다.
예가 될 수 있습니다. 나는 사용자의 화이트 보드와 사용자의 의견을 결합한 쿼리 세트를 가지고있다. 최근에 새 화이트 보드의 객체가 생성 된 경우 다른 주석을 작성합니다. 코멘트는 대신이
난 당신이 아이디어를 얻을 수 있기를 바랍니다 다른 모델에 있었기 때문에 페이지가 매겨진 아래로 더 다른 모든 의견에 표시된의 화이트 보드의 객체 후 매김 표시 할 것 내가 views.py에게
01,238 :)를 달성 내 모듈의부품
class WhiteBoard(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
created = models.DateTimeField(auto_now_add=True)
picture = models.OneToOneField('Picture',related_name='picture',blank=True,null=True)
def __unicode__(self):
return self.name
class Comment(models.Model):
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
body = models.TextField()
picture = models.ForeignKey(Picture)
노력하고있어의
archive.html
{% for post in posts.object_list %}
{{post.name }}
<br>
{{post.body}}
{% endfor %}
<!-- Next/Prev page links -->
{% if posts.object_list and posts.paginator.num_pages > 1 %}
<div class="pagination" style="margin-top: 20px; margin-left: -20px; ">
<span class="step-links">
{% if posts.has_previous %}
<a href= "?page={{ posts.previous_page_number }}">newer entries << </a>
{% endif %}
<span class="current">
Page {{ posts.number }} of {{ posts.paginator.num_pages }}
</span>
{% if posts.has_next %}
<a href="?page={{ posts.next_page_number }}"> >> older entries</a>
{% endif %}
</span>
</div>
{% endif %}
</div>
@catherine 임 그냥 주위에 일 처리 조합 :) – donkeyboy72
@ 캐서린 당신이 말한 장바구니에 글꼴을 추가하려고하는데이 오류가 발생했습니다. float에 vert 문자열 : – donkeyboy72
이것이 도움이 될지 모르겠다, 그것은 데이터를 정렬합니다. http://stackoverflow.com/questions/431628/how-to-combine-2-or-more-querysets-in-a-django-view – catherine