title: How to create dropdown menu from model in django
body: <p>I'm currently trying to create a drop-down menu for my Post categories in my base.html so that it gets displayed on every one of my templates.
  Later on, I want a user to simply click on a category item and get forwarded to the specific category.</p>
  
  <p>I'm a bit confused as to what I should include in my forms and how to call that form in my base.html.</p>
  
  <p><strong>base.html</strong></p>
  
  <pre><code>...
  &lt;body&gt;
          &lt;div class="page-header"&gt;
              {% if user.is_authenticated %}
              &lt;a href="{% url 'logout' %}" class="top-menu"&gt;&lt;button type="button" class="btn btn-danger"&gt;Logout&lt;/button&gt;&lt;/a&gt;
              &lt;a href="{% url 'logout' %}" class="top-menu"&gt;&lt;button type="button" class="btn btn-default"&gt;Account&lt;/button&gt;&lt;/a&gt;
              &lt;a href="{% url 'post_new' %}" class="top-menu"&gt;&lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;&lt;/a&gt;
              {% endif %}
  
  
              {% if user.is_anonymous %}
              &lt;a href="{% url 'signup' %}" class="top-menu"&gt;&lt;button type="button" class="btn btn-success"&gt;Sign-Up&lt;/button&gt;&lt;/a&gt;
              &lt;a href="{% url 'login' %}" class="top-menu"&gt;&lt;button type="button" class="btn btn-primary"&gt;Login&lt;/button&gt;&lt;/a&gt;
              {% endif %}
  
          &lt;div class="fieldWrapper"&gt;
              &lt;label for="{{ category_form.category.id_for_label }}"&gt;Select a category:&lt;/label&gt;
              {{ category_form.category }}
          &lt;/div&gt;
  </code></pre>
  
  <p><strong>views.py:</strong></p>
  
  <pre><code>from .forms import PostForm
  
  
  def category_dropdown(request):
      return render (request, 'quickblog/base.html')
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>...
  # Categorys of Post Model
  class Category(models.Model):
      title = models.CharField(max_length=255, verbose_name="Title")
      description = models.TextField(max_length=1000, null=True)
      categorycover = fields.ImageField(upload_to='categorycovers/', blank=True, null=True, dependencies=[
          FileDependency(processor=ImageProcessor(
              format='JPEG', scale={'max_width': 600, 'max_height': 600}))
      ])
  
      class Meta:
          verbose_name = "Category"
          verbose_name_plural = "Categories"
          ordering = ['title']
  
      def __str__(self):
          return self.title
  
  #Post Model
  class Post(models.Model):
      author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
      title = models.CharField(max_length=200)
      text = models.TextField(max_length=10000)
      category = models.ForeignKey(Category, verbose_name="Category", on_delete=models.CASCADE, null=True)
      tag = models.CharField(max_length=50, blank=True)
  ...
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class PostForm(forms.ModelForm):
      class Meta:
          model = Post
          fields = ['title', 'text', 'category', 'tag', 'postcover', 'postattachment',]
      captcha = CaptchaField()
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>...
  TEMPLATE_CONTEXT_PROCESSORS = (
  'django.core.context_processors.auth',
  'django.core.context_processors.debug',
  'django.core.context_processors.i18n',
  'quickblog.quickblog.context_processors.category_form',
  )
  ...
  </code></pre>
  
  <p><strong>context_processor.py</strong></p>
  
  <pre><code>from .forms import PostForm
  
  def category_form(request):
      form = PostForm()
      return {'category_form': form}
  </code></pre>
  
  <p>Thanks :)</p>