I'm still a bit confused how to make my ordering work, I can't find examples that order things the way I want :(
1.)
My webpage now look like this after playing with the Viewpage.
localhost:8000/navi_polls/madara/1/
<h1>Page</h1>
<!-- Filter 5 -->
* Page - Leafy 2 = 18 votes
* Page - Leafy 3 = 50 votes
<!-- Filter 4b -->
* Paper - Leaf = 300 votes
* Page - Leafy 3 = 50 votes
* Page - Leafy 2 = 18 votes
* Paper - Leafy = 0 votes
2.)
altword_list.html
<h1>{{ poll.rosword }}</h1>
<!-- Filter 5 -->
<ul>
<!-- poll.altword_set.all.order_by('-votes') -->
{% for choice in poll.altword_set.all %}
<li>{{ choice.rosword }} - {{ choice.alt_ros_word }} - {{ choice.alt_transl_word }} - {{ choice.articulate }} = {{ choice.votes }} votes</li>
{% endfor %}
</ul>
<!-- Filter 4b -->
<ul>
{% for choice in filter_4b %}
<li>{{ choice.rosword }} - {{ choice.alt_ros_word }} - {{ choice.alt_transl_word }} - {{ choice.articulate }} = {{ choice.votes }} votes</li>
{% endfor %}
</ul>
3.)
How can I make Filter 5 behave like Filter 4b?
4.)
index.html
<article>
<h1>Filter 2</h1><!-- Filter 2 -->
<h3>(Word)</h3>
{% if filter_2 %}
<ul>
{% for row in filter_2 %}
<li><a href="{% url 'navi_polls:altword_list'
row.id %}">{{ row.rosword }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
</article>
5.)
IndexView
class IndexView(generic.ListView):
template_name = 'navi_polls/index.html'
context_object_name = 'latest_poll_list'
def get_queryset(self):
# Filter 1
"""
Return the last five published polls
(not including those set to be published in the future).
"""
return Word.objects.filter(pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]
#"""
#Return the last five published polls
#(including those set to be published in the future).
#"""
#return Word.objects.order_by('-pub_date')[:5]
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
# Filter 2
filter_2 = Word.objects.filter(direct_transl_word='')
# Filter 4
filter_4 = Altword.objects.filter(rosword__direct_transl_word='')
context.update({
"filter_2": filter_2,
"filter_4": filter_4
})
return context
6.)
AltwordlistView
class AltwordlistView(generic.DetailView):
model = Word
template_name = 'navi_polls/altword_list.html'
context_object_name = 'poll'
def get_queryset(self):
#"""
#Excludes any polls that aren't published yet.
#"""
#return Word.objects.filter(pub_date__lte=timezone.now())
# Filter 5
return Word.objects.filter(direct_transl_word='')
#return Altword.objects.filter(rosword__direct_transl_word='')
def get_context_data(self, **kwargs):
context = super(AltwordlistView, self).get_context_data(**kwargs)
# Filter 4b
filter_4b = Altword.objects.filter(rosword__direct_transl_word='').order_by('-votes')
context.update({
"filter_4b": filter_4b
})
return context
7.)
Models
class Word(models.Model):
rosword = models.CharField(max_length=200)
direct_transl_word = models.CharField(max_length=120, blank=True, null=True)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.rosword
def was_published_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date < now
# Enables future date selection.
#return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
#_______________________________________________________________________________
class Altword(models.Model):
rosword = models.ForeignKey(Word)
alt_ros_word = models.CharField(max_length=200)
alt_transl_word = models.CharField(max_length=200)
articulate = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.alt_ros_word
#_______________________________________________________________________________