title: Bootstrap navbar dropdown populated with database entries in Django 2
body: <p>I am trying to populate a navbar "dropdown-menu" with individual "dropdown-item"'s populated from data in the sqlite3 DB.</p>
  
  <p>I have something similar working on other pages but I cant get it to work in my navbar.</p>
  
  <p>I am creating a record label, and want the list of artists populated from entries in the DB. I have found one tutorial on doing something similar in php, but doesn't translate, and there doesn't seem to be anything either on youtube or here other than populating form data.</p>
  
  <p>Any help is greatly appreciated, as I have been trying to get it working for about a week now. I know it should be simple, but im missing something.</p>
  
  <p>the app is called "music"</p>
  
  <p>models.py</p>
  
  <pre><code>class Artist(models.Model):
      artist_name = models.CharField(max_length=250, default='')
      artist_logo = models.FileField()
      artist_url = models.URLField(blank=True)
  
      def __str__(self):
          return self.artist_name
  
  class Release(models.Model):
      artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
      release_title = models.CharField(max_length=500)
      release_cover = models.FileField()
      release_duration = models.IntegerField()
  
      def __str__(self):
          return self.release_title
  
  class Track(models.Model):
      release = models.ForeignKey(Release, default='', on_delete=models.CASCADE)
      artist = models.ForeignKey(Artist, default='', on_delete=models.CASCADE)
      track_title = models.CharField(max_length=200)
      track_version = models.CharField(max_length=200)
      track_genre = models.CharField(max_length=100)
      track_duration = models.IntegerField()
      track_number = models.SmallIntegerField()
  
      class Meta:
          ordering = ["track_number"]
  
      def __str__(self):
          return self.track_title
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.contrib.auth import authenticate, login
  from django.views import generic
  from django.views.generic import ListView, View
  from .models import Artist, Track, Release
  from .forms import UserForm
  
  # class IndexView(ListView):
  #     template_name = 'music/index.html'
  
  class ReleaseView(generic.ListView):
      template_name = 'music/releaselist.html'
      context_object_name = 'all_releases'
  
      def get_queryset(self):
          return Release.objects.all()
  
  class ArtistView(generic.ListView):
      model = Artist
      template_name = 'music/artistlist.html'
      context_object_name = 'all_artists'
  
      def get_queryset(self):
          return Artist.objects.all()
  
  class DetailView(generic.DetailView):
      model = Release
      template_name = 'music/detail.html'
  </code></pre>
  
  <p>urls.py (Main)</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path, include, re_path
  from django.conf import settings
  from django.conf.urls.static import static
  
  urlpatterns = [
      path('admin/', admin.site.urls),
  # include urls from the music app
      path('music/', include('music.urls'))
  </code></pre>
  
  <p>urls.py ("music" aka the app urls)</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path, include, re_path
  from . import views
  
  # defined the app name in case the same fields are used in other apps
  app_name = 'music'
  
  urlpatterns = [
      # no info past music return index EG /music/
      # path('', views.IndexView.as_view(), name='index'),
      # albums/releases
      re_path(r'^release/$', views.ReleaseView.as_view(), name='release'),
      # looking for music page with album id afterwards /music/1
      re_path(r'^(?P&lt;pk&gt;[0-9]+)/$', views.DetailView.as_view(), name="detail"),
      re_path(r'^(?P&lt;pk&gt;[0-9]+)/$', views.ArtistView.as_view(), name="artist"),
  </code></pre>
  
  <p>base.html</p>
  
  <pre><code>      &lt;li class="nav-item dropdown"&gt;
          &lt;a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;
            Artists
          &lt;/a&gt;
          &lt;div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"&gt;
              {% for artist in all_artists %}
                  &lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;{{ artist.artist_id }}&lt;/a&gt;&lt;/li&gt;
              {% endfor %}
          &lt;/div&gt;
  
        &lt;/li&gt;
  </code></pre>
  
  <p>Update:
  Here is my releases.html which works using similar code, and at the bottom has a test which looks like the for loop is incorrect</p>
  
  <pre><code>{% extends 'music/base.html' %}
  {% block title %}KOLD FUZEON: Releases{% endblock %}
  
  {% block body %}
  
          {% if all_releases %}
              &lt;ul&gt;
                  {% for release in all_releases %}
                      &lt;div class="releaseitem"&gt;
                          &lt;li&gt;&lt;a href="{% url 'music:detail' release.id %}"&gt;{{ release.artist }} - {{ release.release_title }}&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href="{% url 'music:detail' release.id %}"&lt;/a&gt;&lt;img src="{{ release.release_cover.url }}" style="width: 300px"&gt;&lt;/li&gt;
                      &lt;/div&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% else %}
              &lt;h3&gt;We currently dont have any releases yet.&lt;/h3&gt;
          {% endif %}
  
  
  {#basic test for the artist list to be printed to screen#}
              &lt;ul&gt;
                  &lt;li&gt;test1&lt;/li&gt;
                  {% for artist in all_artists %}
                      &lt;li&gt;test2&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
  
  
  
  {% endblock %}
  </code></pre>