Robin
Robin

Reputation: 5486

Django-endless-pagination twitter style pagination not working

I am using django-endless-pagination for my project. But its not working as it is supposed to. Neither is it showing the show more or neither does it work when I change the code to onscroll mode.

<script>$.endlessPaginate({paginateOnScroll: true});</script>

However the include tags are working as its showing the snaps in the template. And even both the scripts (i.e. the jquery and endless.js) are there. What am I missing? Your help and guidance will be very much appreciated. Thank you.

models.py:

class SnapGroup(models.Model):
    name = models.CharField(max_length=150, blank=True, null=True)
    date = models.DateField(default=date.today)

class Snap(models.Model):
    date = models.ForeignKey(SnapGroup)
    image = models.ImageField(upload_to=get_upload_file_name)
    caption = models.CharField(max_length=150, blank=True, null=True)

views.py:

@page_template('snapgroups.html')  # just add this decorator
def snaps(
        request, template='snaps.html', extra_context=None):
    context = {
        'snapgroup': SnapGroup.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(
        template, context, context_instance=RequestContext(request))

snaps.html:

    {% if snapgroup.count > 0 %}

        <div class="endless_page_template">
            {% include page_template %}
        </div>


        {% block js %}
            {{ block.super }}
            <script src="http://code.jquery.com/jquery-latest.js"></script>
            <script src="{{ STATIC_URL }}endless_pagination/js/endless-pagination.js"></script>
            <script>$.endlessPaginate();</script>
        {% endblock %}            

    {% else %}
        <li><p>No SNAPGROUP yet!</p></li>
        <span class="clear_both"></span>
    {% endif %}

snapgroups.html:

{% load endless %}

{% paginate snapgroup %}
{% for sg in snapgroup %}
    <h4 id="combination" class="snap_date">{{sg.date|date:'l'}}, {{sg.date}}</h4>
    <ul>
    {% for snap in sg.snap_set.all %}
        <li><a href="{{MEDIA_URL}}{{snap.image}}" data-imagelightbox="f"><img src="{{MEDIA_URL}}{{snap.image}}" alt="{{snap.caption}}" /></a></li>
    {% endfor %}
        <span class="clear_both"></span>
    </ul>
{% endfor %}

{% show_more %}

Upvotes: 2

Views: 240

Answers (1)

Robin
Robin

Reputation: 5486

Solved my problem by this post. Hope this will help someone else.

Upvotes: 0

Related Questions