title: Opinion: Where to put this code in django app:
body: <p>Trying to figure out the best way to accomplish this. I have inhereted a Django project that is pretty well done. </p>
  
  <p>There are a number of pre coded modules that a user can include in a page's (a page and a module are models in this app) left well in the admin (ie: side links, ads, constant contact). </p>
  
  <p>A new requirement involves inserting a module of internal links in the same well. These links are not associated with a page in the same way the other modules, they are a seperate many to many join - ie one link can be reused in a set across all the pages.</p>
  
  <p>the template pseudo code is:</p>
  
  <pre><code>if page has modules:
   loop through modules:
    write the pre coded content of module
  </code></pre>
  
  <p>Since the links need to be in the same well as the modules, I have created a "link placeholder module" with a slug of link-placeholder.</p>
  
  <p>The new pseudo code is:</p>
  
  <pre><code>if page has modules:
   loop through modules:
    if module.slug is "link-placeholder":
      loop through page.links and output each
    else:
      write pre-coded module
  </code></pre>
  
  <p>My question is where is the best place to write this output for the links? As I see it, my options are:</p>
  
  <ol>
  <li>Build the out put in the template (easy, but kind of gets messy - code is nice and neat now)</li>
  <li>Build a function in the page model that is called when the "link placeholder is encountered) page.get_internal_link_ouutput. Essentially this would query, build and print internal link module output.</li>
  <li>Do the same thing with a custom template tag.</li>
  </ol>
  
  <p>I am leaning towards 2 or 3, but it doesn't seem like the right place to do it. I guess I sometimes get a little confused about the best place to put code in django apps, though I do really like the framework.</p>
  
  <p>Thanks in advance for any advice.</p>