title: How do I access a model outside of a view in Django?
body: <p>I am creating a database site and one of the desired features is to have a button in the navbar that will that the user to a random object in a model. The Django Cookbook gives <a href="http://books.agiliq.com/projects/django-orm-cookbook/en/latest/random.html" rel="nofollow noreferrer">an example of a random function for a model</a>, which I implemented.</p>
  
  <p>However, I cannot seem to call this function from the navbar, since the navbar is in a separate html file that is <code>included</code> above the <code>{% block content %}</code>, which allows it to appear on every page of the site. However, this means it never sees the model object itself, so I cannot access the function with <code>{{object.get_random}}</code> in the navbar.</p>
  
  <p>One idea I had was to use a link in the navbar like this</p>
  
  <pre><code>&lt;a href="{% url 'roma:category_list.object.get_random.get_absolute_url' %}"&gt;Random Category&lt;/a&gt;
  </code></pre>
  
  <p>where <code>category_list</code> is the view that has the model passed to it. From there I hoped to grab an object from the model, then the <code>get_random</code> function, and finally the url from the object returned from the <code>get_random</code> function.
  This obviously does not work.
  Is there a solution that will allow me to access the function in the navbar html?</p>