Simple Flatpage Navigation Items

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# models.py

from django.db import models
from django.contrib.flatpages.models import FlatPage

class FlatpageNav(models.Model):
    '''
    A simple snippet of HTML that can be associated with multiple FlatPages.
    '''
    flatpages = models.ManyToManyField(FlatPage, \
        help_text='Select the Flatpages that should display this menu')
    name = models.CharField(max_length=255, \
        help_text='A name for this menu. This is not displayed on the FlatPage.')
    menu = models.TextField(help_text='Enter an HTML snippet for the menu.')

    def __unicode__(self):
        return u"%s"%self.name

# admin.py
from models import FlatpageNav
from django.contrib import admin

class FlatpageNavAdmin(admin.ModelAdmin):
    list_display = ('name', )

admin.site.register(FlatpageNav, FlatpageNavAdmin)

# Then, in your Flatpage default template, add the following:
    {% if flatpage.flatpagenav_set.count %}
        {% for nav in flatpage.flatpagenav_set.all %}
            {{ nav.menu|safe }}
        {% endfor %}
    {% else %}
         {# Include an alternative menu. #}
        {% include "flatpages/menu.html" %}
    {% endif %}

More like this

  1. Non-Javascript select list navigator by shacker 5 years ago
  2. Restrict Flatpage To Group by nikolaj 6 years ago
  3. Class-based view mixin for flatpages by schwuk 1 year, 1 month ago
  4. Breadcrumbs for flatpages by jca 6 years, 3 months ago
  5. Row-Level, URL-based permissions for FlatPages by bradmontgomery 4 years, 10 months ago

Comments

(Forgotten your password?)