<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django-generic-images's documentation &mdash; django-generic-images v0.35 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.35',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="django-generic-images v0.35 documentation" href="" />
    <link rel="next" title="Upgrade notes" href="upgrade.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="upgrade.html" title="Upgrade notes"
             accesskey="N">next</a> |</li>
        <li><a href="">django-generic-images v0.35 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="django-generic-images-s-documentation">
<h1>django-generic-images&#8217;s documentation<a class="headerlink" href="#django-generic-images-s-documentation" title="Permalink to this headline">¶</a></h1>
<p>django-generic-images is a generic images pluggable django app.</p>
<p>This app provides image model (useful managers, methods and fields)
that can be attached to any other Django model using generic relations.
It also provides admin multi-image uploader (based on
<a class="reference" href="http://bitbucket.org/kmike/gearsuploader/">GearsUploader</a> ) with client-side
image resizing, animated progress bar and before-upload image previews.</p>
<p>Requirements: django 1.1 (or trunk).</p>
<p><a class="reference" href="http://bitbucket.org/daevaorn/django-composition/">django-composition</a> is
required if you want to use
<a title="generic_images.fields.ImageCountField" class="reference" href="#generic_images.fields.ImageCountField"><tt class="xref docutils literal"><span class="pre">ImageCountField</span></tt></a> or
<a title="generic_images.fields.UserImageCountField" class="reference" href="#generic_images.fields.UserImageCountField"><tt class="xref docutils literal"><span class="pre">UserImageCountField</span></tt></a>.</p>
<p>There is an image gallery app
(<a class="reference" href="http://bitbucket.org/kmike/django-photo-albums/">django-photo-albums</a>)
based on django-generic-images.</p>
<ul>
<li class="toctree-l1"><a class="reference" href="upgrade.html">Upgrade notes</a><ul>
<li class="toctree-l2"><a class="reference" href="upgrade.html#from-0-35-7-to-0-35-8">From 0.35.7 to 0.35.8</a></li>
</ul>
</li>
</ul>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><pre>$ pip install django-generic-images</pre>
</div>
<p>or:</p>
<div class="highlight-python"><pre>$ easy_install django-generic-images</pre>
</div>
<p>or:</p>
<div class="highlight-python"><pre>$ hg clone http://bitbucket.org/kmike/django-generic-images/
$ cd django-generic-images
$ python setup.py install</pre>
</div>
<p>Then add &#8216;generic_images&#8217; to your <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> in settings.py and run</p>
<div class="highlight-python"><pre>$ manage.py syncdb</pre>
</div>
<p>If you want <tt class="docutils literal"><span class="pre">ImageCountField</span></tt> and <tt class="docutils literal"><span class="pre">UserImageCountField</span></tt> then follow
installation instructions at  <a class="reference" href="http://bitbucket.org/daevaorn/django-composition/">http://bitbucket.org/daevaorn/django-composition/</a>
to install django-composition.</p>
<p>For admin uploader to work <tt class="docutils literal"><span class="pre">generic_images</span></tt> folder from
<tt class="docutils literal"><span class="pre">generic_images/media/</span></tt> should be copied to project&#8217;s <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt>.</p>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<div class="section" id="generic-images">
<h3>Generic Images<a class="headerlink" href="#generic-images" title="Permalink to this headline">¶</a></h3>
<p>The idea is to provide an infrastructure for images that can be attached
to any django model using generic relations.</p>
<div class="section" id="models">
<h4>Models<a class="headerlink" href="#models" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_images.models.AttachedImage">
<em class="property">
class </em><tt class="descclassname">generic_images.models.</tt><tt class="descname">AttachedImage</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.models.AttachedImage" title="Permalink to this definition">¶</a></dt>
<dd>Image model that can be attached to any other Django model using
generic relations. It is simply non-abstract subclass of
<a title="generic_images.models.AbstractAttachedImage" class="reference" href="#generic_images.models.AbstractAttachedImage"><tt class="xref docutils literal"><span class="pre">AbstractAttachedImage</span></tt></a></dd></dl>

<dl class="class">
<dt id="generic_images.models.AbstractAttachedImage">
<em class="property">
class </em><tt class="descclassname">generic_images.models.</tt><tt class="descname">AbstractAttachedImage</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="generic_images.models.ReplaceOldImageModel" class="reference" href="#generic_images.models.ReplaceOldImageModel"><tt class="xref docutils literal"><span class="pre">generic_images.models.ReplaceOldImageModel</span></tt></a>, <a title="generic_utils.models.GenericModelBase" class="reference" href="#generic_utils.models.GenericModelBase"><tt class="xref docutils literal"><span class="pre">generic_utils.models.GenericModelBase</span></tt></a></p>
<p>Abstract Image model that can be attached to any other Django model
using generic relations.</p>
<dl class="attribute">
<dt id="AbstractAttachedImage.is_main">
<tt class="descname">is_main</tt><a class="headerlink" href="#AbstractAttachedImage.is_main" title="Permalink to this definition">¶</a></dt>
<dd>BooleanField. Whether the image is the main image for object.
This field is set to False automatically for all images attached to
same object if image with is_main=True is saved to ensure that there
is only 1 main image for object.</dd></dl>

<dl class="attribute">
<dt id="AbstractAttachedImage.order">
<tt class="descname">order</tt><a class="headerlink" href="#AbstractAttachedImage.order" title="Permalink to this definition">¶</a></dt>
<dd>IntegerField to support ordered image sets.
On creation it is set to max(id)+1.</dd></dl>

<dl class="method">
<dt id="generic_images.models.AbstractAttachedImage.get_file_name">
<tt class="descname">get_file_name</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.get_file_name" title="Permalink to this definition">¶</a></dt>
<dd>Returns file name (without path and extenstion)
for uploaded image. Default is &#8216;max(pk)+1&#8217;.
Override this in subclass or assign another functions per-instance
if you want different file names (ex: random string).</dd></dl>

<dl class="method">
<dt id="generic_images.models.AbstractAttachedImage.get_order_in_album">
<tt class="descname">get_order_in_album</tt><big>(</big><em>reversed_ordering=True</em><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.get_order_in_album" title="Permalink to this definition">¶</a></dt>
<dd>Returns image order number. It is calculated as (number+1) of images
attached to the same content_object whose order is greater
(if &#8216;reverse_ordering&#8217; is True) or lesser (if &#8216;reverse_ordering&#8217; is
False) than image&#8217;s order.</dd></dl>

<dl class="method">
<dt id="generic_images.models.AbstractAttachedImage.get_upload_path">
<tt class="descname">get_upload_path</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.get_upload_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Override this in proxy subclass to customize upload path.
Default upload path is
<tt class="docutils literal"><span class="pre">/media/images/&lt;user.id&gt;/&lt;filename&gt;.&lt;ext&gt;</span></tt>
or <tt class="docutils literal"><span class="pre">/media/images/common/&lt;filename&gt;.&lt;ext&gt;</span></tt> if user is not set.</p>
<p><tt class="docutils literal"><span class="pre">&lt;filename&gt;</span></tt> is returned by
<a title="generic_images.models.AbstractAttachedImage.get_file_name" class="reference" href="#generic_images.models.AbstractAttachedImage.get_file_name"><tt class="xref docutils literal"><span class="pre">get_file_name()</span></tt></a>
method. By default it is probable id of new image (it is
predicted as it is unknown at this stage).</p>
</dd></dl>

<dl class="method">
<dt id="generic_images.models.AbstractAttachedImage.next">
<tt class="descname">next</tt><big>(</big><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.next" title="Permalink to this definition">¶</a></dt>
<dd>Returns next image for same content_object and None if image is
the last.</dd></dl>

<dl class="method">
<dt id="generic_images.models.AbstractAttachedImage.previous">
<tt class="descname">previous</tt><big>(</big><big>)</big><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.previous" title="Permalink to this definition">¶</a></dt>
<dd>Returns previous image for same content_object and None if image
is the first.</dd></dl>

<dl class="attribute">
<dt id="generic_images.models.AbstractAttachedImage.content_object">
<tt class="descname">content_object</tt><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.content_object" title="Permalink to this definition">¶</a></dt>
<dd>Provides a generic relation to any object through content-type/object-id
fields.</dd></dl>

<dl class="attribute">
<dt id="generic_images.models.AbstractAttachedImage.objects">
<tt class="descname">objects</tt><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.objects" title="Permalink to this definition">¶</a></dt>
<dd>Default manager of <a title="generic_images.managers.AttachedImageManager" class="reference" href="#generic_images.managers.AttachedImageManager"><tt class="xref docutils literal"><span class="pre">AttachedImageManager</span></tt></a>
type.</dd></dl>

<dl class="attribute">
<dt id="generic_images.models.AbstractAttachedImage.user">
<tt class="descname">user</tt><a class="headerlink" href="#generic_images.models.AbstractAttachedImage.user" title="Permalink to this definition">¶</a></dt>
<dd>A ForeignKey to associated user, for example user who uploaded image.
Can be empty.</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_images.models.BaseImageModel">
<em class="property">
class </em><tt class="descclassname">generic_images.models.</tt><tt class="descname">BaseImageModel</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.models.BaseImageModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Simple abstract Model class with image field.</p>
<dl class="attribute">
<dt id="BaseImageModel.image">
<tt class="descname">image</tt><a class="headerlink" href="#BaseImageModel.image" title="Permalink to this definition">¶</a></dt>
<dd><tt class="docutils literal"><span class="pre">models.ImageField</span></tt></dd></dl>

<dl class="method">
<dt id="generic_images.models.BaseImageModel.get_upload_path">
<tt class="descname">get_upload_path</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#generic_images.models.BaseImageModel.get_upload_path" title="Permalink to this definition">¶</a></dt>
<dd>Override this to customize upload path</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_images.models.ReplaceOldImageModel">
<em class="property">
class </em><tt class="descclassname">generic_images.models.</tt><tt class="descname">ReplaceOldImageModel</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.models.ReplaceOldImageModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="generic_images.models.BaseImageModel" class="reference" href="#generic_images.models.BaseImageModel"><tt class="xref docutils literal"><span class="pre">generic_images.models.BaseImageModel</span></tt></a></p>
<p>Abstract Model class with image field.
If the file for image is re-uploaded, old file is deleted.</p>
</dd></dl>

</div>
<div class="section" id="module-generic_images.admin">
<h4>Admin<a class="headerlink" href="#module-generic_images.admin" title="Permalink to this headline">¶</a></h4>
<dl class="attribute">
<dt id="generic_images.admin.AttachedImageAdminForm">
<tt class="descclassname">generic_images.admin.</tt><tt class="descname">AttachedImageAdminForm</tt><a class="headerlink" href="#generic_images.admin.AttachedImageAdminForm" title="Permalink to this definition">¶</a></dt>
<dd><p>Form for AttachedImage model to be used in inline admin</p>
<p>alias of <tt class="xref docutils literal"><span class="pre">_AttachedImageAdminForm</span></tt></p>
</dd></dl>

<dl class="attribute">
<dt id="generic_images.admin.AttachedImagesInline">
<tt class="descclassname">generic_images.admin.</tt><tt class="descname">AttachedImagesInline</tt><a class="headerlink" href="#generic_images.admin.AttachedImagesInline" title="Permalink to this definition">¶</a></dt>
<dd><p>InlineModelAdmin for attached images.
Adds multi-image uploader with progress bar, before-upload image
previews and client-side resizing. Uploader is based
on GearsUploader (<a class="reference" href="http://bitbucket.org/kmike/gearsuploader/">http://bitbucket.org/kmike/gearsuploader/</a>) project.</p>
<p>To make this work copy <tt class="docutils literal"><span class="pre">generic_images</span></tt> folder from
<tt class="docutils literal"><span class="pre">generic_images/media/</span></tt> to your <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt>. Then use
<tt class="docutils literal"><span class="pre">AttachedImagesInline</span></tt> class for you inlines:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#admin.py</span>

<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">generic_images.admin</span> <span class="kn">import</span> <span class="n">AttachedImagesInline</span>

<span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">AttachedImagesInline</span><span class="p">]</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">MyModel</span><span class="p">,</span> <span class="n">MyModelAdmin</span><span class="p">)</span>
</pre></div>
</div>
<p>Just before standard formset the following uploader is displayed:</p>
<img alt="_images/admin-with-formset.png" src="_images/admin-with-formset.png" />
<p>Gears plugin is here</p>
<img alt="_images/admin-nogears.png" src="_images/admin-nogears.png" />
<p>Message is displayed if Gears plugin is not available</p>
<img alt="_images/admin-previews.png" src="_images/admin-previews.png" />
<p>User can select several files at once using Ctrl or Shift keys
(Cmd on Mac) in standard OS file selection dialog. He can also remove
images from selection by clicking on thumbnails. Several files can also
be selected by opening file selection dialog several times.</p>
<img alt="_images/admin-uploading.png" src="_images/admin-uploading.png" />
<p>User presses &#8216;Upload&#8217; button and upload process begins</p>
<p>By default the &#8216;Resize ..&#8217; checkbox is unchecked and the input field is
blank. If it is unchecked then images are not resized before uploading.
User can check it and set his max image width.</p>
<p>In order to set the default value and mark the checkbox as checked by
default create customized <tt class="docutils literal"><span class="pre">AttachedImagesInline</span></tt> class using
<a title="generic_images.admin.attachedimages_inline_factory" class="reference" href="#generic_images.admin.attachedimages_inline_factory"><tt class="xref docutils literal"><span class="pre">attachedimages_inline_factory()</span></tt></a> function. This function can also be
used to change uploader language (language auto-discovering is not
implemented):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">generic_images.admin</span> <span class="kn">import</span> <span class="n">attachedimages_inline_factory</span>

<span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">attachedimages_inline_factory</span><span class="p">(</span><span class="n">lang</span><span class="o">=</span><span class="s">&#39;ru&#39;</span><span class="p">,</span> <span class="n">max_width</span><span class="o">=</span><span class="mf">1024</span><span class="p">)]</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">MyModel</span><span class="p">,</span> <span class="n">MyModelAdmin</span><span class="p">)</span>
</pre></div>
</div>
<p>alias of <tt class="xref docutils literal"><span class="pre">_AttachedImagesInline</span></tt></p>
</dd></dl>

<dl class="function">
<dt id="generic_images.admin.attachedimage_form_factory">
<tt class="descclassname">generic_images.admin.</tt><tt class="descname">attachedimage_form_factory</tt><big>(</big><em>lang='en'</em><big>)</big><a class="headerlink" href="#generic_images.admin.attachedimage_form_factory" title="Permalink to this definition">¶</a></dt>
<dd>Returns ModelForm class to be used in admin.
&#8216;lang&#8217; is the language for GearsUploader (can be &#8216;en&#8217; and &#8216;ru&#8217; at the
moment).</dd></dl>

<dl class="function">
<dt id="generic_images.admin.attachedimages_inline_factory">
<tt class="descclassname">generic_images.admin.</tt><tt class="descname">attachedimages_inline_factory</tt><big>(</big><em>lang='en'</em>, <em>max_width=''</em><big>)</big><a class="headerlink" href="#generic_images.admin.attachedimages_inline_factory" title="Permalink to this definition">¶</a></dt>
<dd>Returns InlineModelAdmin for attached images.
&#8216;lang&#8217; is the language for GearsUploader (can be &#8216;en&#8217; and &#8216;ru&#8217; at the
moment). &#8216;max_width&#8217; is default resize width parameter to be set in
widget.</dd></dl>

</div>
<div class="section" id="module-generic_images.managers">
<h4>Managers<a class="headerlink" href="#module-generic_images.managers" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_images.managers.AttachedImageManager">
<em class="property">
class </em><tt class="descclassname">generic_images.managers.</tt><tt class="descname">AttachedImageManager</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.managers.AttachedImageManager" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="generic_utils.managers.GenericModelManager" class="reference" href="#generic_utils.managers.GenericModelManager"><tt class="xref docutils literal"><span class="pre">generic_utils.managers.GenericModelManager</span></tt></a></p>
<p>Manager with helpful functions for attached images</p>
<dl class="method">
<dt id="generic_images.managers.AttachedImageManager.get_main_for">
<tt class="descname">get_main_for</tt><big>(</big><em>model</em><big>)</big><a class="headerlink" href="#generic_images.managers.AttachedImageManager.get_main_for" title="Permalink to this definition">¶</a></dt>
<dd>Returns main image for given model</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_images.managers.ImagesAndUserManager">
<em class="property">
class </em><tt class="descclassname">generic_images.managers.</tt><tt class="descname">ImagesAndUserManager</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.managers.ImagesAndUserManager" title="Permalink to this definition">¶</a></dt>
<dd><p>Useful manager for models that have AttachedImage (or subclass) field
and &#8216;injector=GenericIngector()&#8217; manager.</p>
<dl class="method">
<dt id="generic_images.managers.ImagesAndUserManager.select_with_main_images">
<tt class="descname">select_with_main_images</tt><big>(</big><em>limit=None</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_images.managers.ImagesAndUserManager.select_with_main_images" title="Permalink to this definition">¶</a></dt>
<dd>Select all objects with filters passed as kwargs.   
For each object it&#8217;s main image instance is accessible as <tt class="docutils literal"><span class="pre">object.main_image</span></tt>.
Results can be limited using <tt class="docutils literal"><span class="pre">limit</span></tt> parameter.
Selection is performed using only 2 or 3 sql queries.</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-generic_images.forms">
<h4>Forms<a class="headerlink" href="#module-generic_images.forms" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_images.forms.AttachedImageForm">
<em class="property">
class </em><tt class="descclassname">generic_images.forms.</tt><tt class="descname">AttachedImageForm</tt><a class="headerlink" href="#generic_images.forms.AttachedImageForm" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref docutils literal"><span class="pre">django.forms.models.ModelForm</span></tt></p>
<p>Simple form for AttachedImage model with <tt class="docutils literal"><span class="pre">image</span></tt> and <tt class="docutils literal"><span class="pre">caption</span></tt> fields.</p>
</dd></dl>

</div>
<div class="section" id="module-generic_images.fields">
<h4>Fields for denormalisation<a class="headerlink" href="#module-generic_images.fields" title="Permalink to this headline">¶</a></h4>
<p>django-generic-images provides fields for storing information about 
attached images count. Value is stored in model that images are 
attached to. Value is updated automatically when image is saved or deleted.
Access to this value is much faster than additional &#8220;count()&#8221; queries.</p>
<dl class="class">
<dt id="generic_images.fields.ImageCountField">
<em class="property">
class </em><tt class="descclassname">generic_images.fields.</tt><tt class="descname">ImageCountField</tt><big>(</big><em>native=None</em><big>)</big><a class="headerlink" href="#generic_images.fields.ImageCountField" title="Permalink to this definition">¶</a></dt>
<dd><p>Field with model&#8217;s attached images count.
Value of this field is updated automatically when 
image is added or removed. Access to this field
doesn&#8217;t produce additional &#8216;select count(*)&#8217; query,
data is stored in table.</p>
<p>Example 1:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">generic_images.fields</span> <span class="kn">import</span> <span class="n">ImageCountField</span>

<span class="k">class</span> <span class="nc">MyModel1</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="c">#... fields definitions</span>
    <span class="n">image_count</span> <span class="o">=</span> <span class="n">ImageCountField</span><span class="p">()</span>
</pre></div>
</div>
<p>Example 2:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModel2</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="c">#... fields definitions</span>
    <span class="n">image_count</span> <span class="o">=</span> <span class="n">ImageCountField</span><span class="p">(</span><span class="n">native</span><span class="o">=</span><span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">(</span><span class="s">u&#39;MyModel2 Images count&#39;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mf">0</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="class">
<dt id="generic_images.fields.UserImageCountField">
<em class="property">
class </em><tt class="descclassname">generic_images.fields.</tt><tt class="descname">UserImageCountField</tt><big>(</big><em>native=None</em>, <em>user_attr='user'</em><big>)</big><a class="headerlink" href="#generic_images.fields.UserImageCountField" title="Permalink to this definition">¶</a></dt>
<dd><p>Field that should be put into user&#8217;s profile (AUTH_PROFILE_MODULE). 
It will contain number of images that are attached to corresponding User.</p>
<p>This field is useful when you want to use something like 
<a title="generic_images.fields.ImageCountField" class="reference" href="#generic_images.fields.ImageCountField"><tt class="xref docutils literal"><span class="pre">ImageCountField</span></tt></a> for <tt class="docutils literal"><span class="pre">User</span></tt> model. 
It is not possible to add a field to User model without 
duck punching (monkey patching). <tt class="docutils literal"><span class="pre">UserImageCountField</span></tt> should be 
put into user&#8217;s profile (same model as defined in AUTH_PROFILE_MODULE). 
It will contain number of images that are attached to corresponding User.
FK attribute to User model is considered <tt class="docutils literal"><span class="pre">'user'</span></tt> by default, but this 
can be overrided using <tt class="docutils literal"><span class="pre">user_attr</span></tt> argument to <tt class="docutils literal"><span class="pre">UserImageCountField</span></tt> 
constructor. As with <a title="generic_images.fields.ImageCountField" class="reference" href="#generic_images.fields.ImageCountField"><tt class="xref docutils literal"><span class="pre">ImageCountField</span></tt></a>, 
<tt class="docutils literal"><span class="pre">UserImageCountField</span></tt> constructor accepts also <tt class="docutils literal"><span class="pre">native</span></tt> argument - an 
underlying field.</p>
</dd></dl>

<dl class="function">
<dt id="generic_images.fields.force_recalculate">
<tt class="descclassname">generic_images.fields.</tt><tt class="descname">force_recalculate</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#generic_images.fields.force_recalculate" title="Permalink to this definition">¶</a></dt>
<dd><p>Recalculate all ImageCountField and UserImageCountField fields
in object <tt class="docutils literal"><span class="pre">obj</span></tt>.</p>
<p>This should be used if auto-updating of these fields was disabled for
some reason.</p>
<p>To disable auto-update when saving AttachedImage instance 
(for example when you need to save a lot of images and want to 
recalculate denormalised values only after all images are saved) use 
this pattern:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">image</span> <span class="o">=</span> <span class="n">AttachedImage</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="n">image</span><span class="o">.</span><span class="n">send_signal</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">image</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="module-generic_images.context_processors">
<h4>Context processors<a class="headerlink" href="#module-generic_images.context_processors" title="Permalink to this headline">¶</a></h4>
<dl class="function">
<dt id="generic_images.context_processors.thumbnail_types">
<tt class="descclassname">generic_images.context_processors.</tt><tt class="descname">thumbnail_types</tt><big>(</big><em>request</em><big>)</big><a class="headerlink" href="#generic_images.context_processors.thumbnail_types" title="Permalink to this definition">¶</a></dt>
<dd>A context processor to add possible thumbnail sizes to the current Context.
Useful for managing possible sorl.thumbnails thumbnail&#8217;s sizes</dd></dl>

</div>
</div>
<div class="section" id="generic-utils">
<h3>Generic Utils<a class="headerlink" href="#generic-utils" title="Permalink to this headline">¶</a></h3>
<div class="section" id="module-generic_utils.app_utils">
<h4>Pluggable app utils<a class="headerlink" href="#module-generic_utils.app_utils" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_utils.app_utils.PluggableSite">
<em class="property">
class </em><tt class="descclassname">generic_utils.app_utils.</tt><tt class="descname">PluggableSite</tt><big>(</big><em>instance_name</em>, <em>app_name</em>, <em>queryset=None</em>, <em>object_regex=None</em>, <em>lookup_field=None</em>, <em>extra_context=None</em>, <em>template_object_name='object'</em>, <em>has_edit_permission=&lt;function &lt;lambda&gt; at 0x1d75570&gt;</em>, <em>context_processors=None</em>, <em>object_getter=None</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for reusable apps.
The approach is similar to django AdminSite.
For usage case please check photo_albums app.</p>
<dl class="method">
<dt id="generic_utils.app_utils.PluggableSite.check_permissions">
<tt class="descname">check_permissions</tt><big>(</big><em>request</em>, <em>object</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.check_permissions" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="generic_utils.app_utils.PluggableSite.get_common_context">
<tt class="descname">get_common_context</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.get_common_context" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="generic_utils.app_utils.PluggableSite.make_regex">
<tt class="descname">make_regex</tt><big>(</big><em>url</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.make_regex" title="Permalink to this definition">¶</a></dt>
<dd><p>Make regex string for <tt class="docutils literal"><span class="pre">PluggableSite</span></tt> urlpatterns: prepend url
with parent object&#8217;s url and app name.</p>
<p>See also: <a class="reference" href="http://code.djangoproject.com/ticket/11559">http://code.djangoproject.com/ticket/11559</a>.</p>
</dd></dl>

<dl class="method">
<dt id="generic_utils.app_utils.PluggableSite.patterns">
<tt class="descname">patterns</tt><big>(</big><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.patterns" title="Permalink to this definition">¶</a></dt>
<dd><p>This method should return url patterns (like urlpatterns variable in
<tt class="docutils literal"><span class="pre">urls.py</span></tt>). It is helpful to construct regex with
<a title="generic_utils.app_utils.PluggableSite.make_regex" class="reference" href="#generic_utils.app_utils.PluggableSite.make_regex"><tt class="xref docutils literal"><span class="pre">make_regex()</span></tt></a> method.
Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">return</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;photo_albums.views&#39;</span><span class="p">,</span>
                    <span class="n">url</span><span class="p">(</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">make_regex</span><span class="p">(</span><span class="s">&#39;/&#39;</span><span class="p">),</span>
                        <span class="s">&#39;show_album&#39;</span><span class="p">,</span>
                        <span class="p">{</span><span class="s">&#39;album_site&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="p">},</span>
                        <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;show_album&#39;</span><span class="p">,</span>
                    <span class="p">),</span>
               <span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="generic_utils.app_utils.PluggableSite.reverse">
<tt class="descname">reverse</tt><big>(</big><em>url</em>, <em>args=None</em>, <em>kwargs=None</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.reverse" title="Permalink to this definition">¶</a></dt>
<dd>Reverse an url taking self.app_name in account</dd></dl>

<dl class="attribute">
<dt id="generic_utils.app_utils.PluggableSite.urls">
<tt class="descname">urls</tt><a class="headerlink" href="#generic_utils.app_utils.PluggableSite.urls" title="Permalink to this definition">¶</a></dt>
<dd><p>Use it in <tt class="docutils literal"><span class="pre">urls.py</span></tt>.
Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">url</span><span class="p">(</span><span class="s">r&#39;^my_site/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">my_pluggable_site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="generic_utils.app_utils.get_site_decorator">
<tt class="descclassname">generic_utils.app_utils.</tt><tt class="descname">get_site_decorator</tt><big>(</big><em>site_param='site'</em>, <em>obj_param='obj'</em>, <em>context_param='context'</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.get_site_decorator" title="Permalink to this definition">¶</a></dt>
<dd><p>It is a function that returns decorator factory useful for PluggableSite
views. This decorator factory returns decorator that do some
boilerplate work and make writing PluggableSite views easier.
It passes PluggableSite instance to decorated view,
retreives and passes object that site is attached to and passes
common context. It also passes and all the decorator factory&#8217;s
keyword arguments.</p>
<p>For example usage please check photo_albums.views.</p>
<p>Btw, this decorator seems frightening for me. It feels that
&#8220;views as PluggableSite methods&#8221; approach can easily make this decorator
obsolete. But for now it just works.</p>
</dd></dl>

<dl class="function">
<dt id="generic_utils.app_utils.simple_getter">
<tt class="descclassname">generic_utils.app_utils.</tt><tt class="descname">simple_getter</tt><big>(</big><em>queryset</em>, <em>object_regex=None</em>, <em>lookup_field=None</em><big>)</big><a class="headerlink" href="#generic_utils.app_utils.simple_getter" title="Permalink to this definition">¶</a></dt>
<dd>Returns simple object_getter function for use with PluggableSite.
It takes &#8216;queryset&#8217; with QuerySet or Model instance, &#8216;object_regex&#8217; with
url regex and &#8216;lookup_field&#8217; with lookup field.</dd></dl>

</div>
<div class="section" id="id1">
<h4>Models<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_utils.models.GenericModelBase">
<em class="property">
class </em><tt class="descclassname">generic_utils.models.</tt><tt class="descname">GenericModelBase</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.models.GenericModelBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Abstract base class for models that will be attached using
generic relations.</p>
<dl class="attribute">
<dt id="generic_utils.app_utils.GenericModelBase.object_id">
<tt class="descname">object_id</tt><a class="headerlink" href="#generic_utils.app_utils.GenericModelBase.object_id" title="Permalink to this definition">¶</a></dt>
<dd>A PositiveIntegerField containing the primary key of the object the model
is attached to.</dd></dl>

<dl class="attribute">
<dt id="generic_utils.app_utils.GenericModelBase.content_type">
<tt class="descname">content_type</tt><a class="headerlink" href="#generic_utils.app_utils.GenericModelBase.content_type" title="Permalink to this definition">¶</a></dt>
<dd>A ForeignKey to ContentType; this is the type of the object the model is 
attached to.</dd></dl>

<dl class="attribute">
<dt id="generic_utils.models.GenericModelBase.content_object">
<tt class="descname">content_object</tt><a class="headerlink" href="#generic_utils.models.GenericModelBase.content_object" title="Permalink to this definition">¶</a></dt>
<dd>A GenericForeignKey attribute pointing to the object the comment is
attached to. You can use this to get at the related object
(i.e. my_model.content_object). Since this field is a
GenericForeignKey, it's actually syntactic sugar on top of two underlyin
attributes, described above.</dd></dl>

<dl class="attribute">
<dt id="generic_utils.models.GenericModelBase.injector">
<tt class="descname">injector</tt><a class="headerlink" href="#generic_utils.models.GenericModelBase.injector" title="Permalink to this definition">¶</a></dt>
<dd><a title="generic_utils.managers.GenericInjector" class="reference" href="#generic_utils.managers.GenericInjector"><tt class="xref docutils literal"><span class="pre">GenericInjector</span></tt></a> manager.</dd></dl>

<dl class="attribute">
<dt id="generic_utils.models.GenericModelBase.objects">
<tt class="descname">objects</tt><a class="headerlink" href="#generic_utils.models.GenericModelBase.objects" title="Permalink to this definition">¶</a></dt>
<dd>Default manager. It is of type <a title="generic_utils.managers.GenericModelManager" class="reference" href="#generic_utils.managers.GenericModelManager"><tt class="xref docutils literal"><span class="pre">GenericModelManager</span></tt></a>.</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_utils.models.TrueGenericModelBase">
<em class="property">
class </em><tt class="descclassname">generic_utils.models.</tt><tt class="descname">TrueGenericModelBase</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.models.TrueGenericModelBase" title="Permalink to this definition">¶</a></dt>
<dd>It is similar to <a title="generic_utils.models.GenericModelBase" class="reference" href="#generic_utils.models.GenericModelBase"><tt class="xref docutils literal"><span class="pre">GenericModelBase</span></tt></a> but
with TextField object_id instead of PositiveIntegerField.</dd></dl>

</div>
<div class="section" id="module-generic_utils.managers">
<h4>Generic relation helpers<a class="headerlink" href="#module-generic_utils.managers" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_utils.managers.GenericInjector">
<em class="property">
class </em><tt class="descclassname">generic_utils.managers.</tt><tt class="descname">GenericInjector</tt><big>(</big><em>fk_field='object_id'</em>, <em>ct_field='content_type'</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.managers.GenericInjector" title="Permalink to this definition">¶</a></dt>
<dd><p>RelatedInjector but for GenericForeignKey&#8217;s.
Manager for selecting all generic-related objects in one (two) SQL queries.
Selection is performed for a list of objects. Resulting data is aviable as attribute
of original model. Only one instance per object can be selected. Example usage:
select (and make acessible as user.avatar) all avatars for a list of user when
avatars are AttachedImage&#8217;s attached to User model with is_main=True attributes.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.auth.models</span> <span class="kn">import</span> <span class="n">User</span>
<span class="kn">from</span> <span class="nn">generic_images.models</span> <span class="kn">import</span> <span class="n">AttachedImage</span>

<span class="n">users</span> <span class="o">=</span> <span class="n">User</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()[:</span><span class="mf">10</span><span class="p">]</span>
<span class="n">AttachedImage</span><span class="o">.</span><span class="n">injector</span><span class="o">.</span><span class="n">inject_to</span><span class="p">(</span><span class="n">users</span><span class="p">,</span> <span class="s">&#39;avatar&#39;</span><span class="p">,</span> <span class="n">is_main</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="c"># i=0..9: users[i].avatar is AttachedImage objects with is_main=True.</span>
<span class="c"># If there is no such AttachedImage (user doesn&#39;t have an avatar),</span>
<span class="c"># users[i].avatar is None</span>
</pre></div>
</div>
<dl class="docutils">
<dt>For this example 2 or 3 sql queries will be executed:</dt>
<dd><ol class="first last arabic simple">
<li>one query for selecting 10 users,</li>
<li>one query for selecting all avatars (images with is_main=True) for selected users</li>
<li>and maybe one query for selecting content-type for User model</li>
</ol>
</dd>
</dl>
<p>One can reuse GenericInjector manager for other models that are supposed to
be attached via generic relationship. It can be considered as an addition to
GFKmanager and GFKQuerySet from djangosnippets for different use cases.</p>
<dl class="method">
<dt id="generic_utils.managers.GenericInjector.inject_to">
<tt class="descname">inject_to</tt><big>(</big><em>objects</em>, <em>field_name</em>, <em>get_inject_object=&lt;function &lt;lambda&gt; at 0x1a4a4b0&gt;</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.managers.GenericInjector.inject_to" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">objects</span></tt> is an iterable. Images (or other generic-related model instances)</dt>
<dd>will be attached to elements of this iterable.</dd>
</dl>
<p><tt class="docutils literal"><span class="pre">field_name</span></tt> is the attached object attribute name</p>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">get_inject_object</span></tt> is a callable that takes object in <cite>objects</cite> iterable.</dt>
<dd>Image will be available as an attribute of the result of
<cite>get_injector_object(object)</cite>. Images attached to <cite>get_injector_object(object)</cite>
will be selected.</dd>
</dl>
<p>All other kwargs will be passed as arguments to queryset filter function.</p>
<p>Example: you have a list of comments. Each comment has &#8216;user&#8217; attribute.
You want to fetch 10 comments and their authors with avatars. Avatars should
be accessible as <cite>user.avatar</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">comments</span> <span class="o">=</span> <span class="n">Comment</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span><span class="o">.</span><span class="n">select_related</span><span class="p">(</span><span class="s">&#39;user&#39;</span><span class="p">)[:</span><span class="mf">10</span><span class="p">]</span>
<span class="n">AttachedImage</span><span class="o">.</span><span class="n">injector</span><span class="o">.</span><span class="n">inject_to</span><span class="p">(</span><span class="n">comments</span><span class="p">,</span> <span class="s">&#39;avatar&#39;</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">obj</span><span class="p">:</span> <span class="n">obj</span><span class="o">.</span><span class="n">user</span><span class="p">,</span> <span class="n">is_main</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_utils.managers.GenericModelManager">
<em class="property">
class </em><tt class="descclassname">generic_utils.managers.</tt><tt class="descname">GenericModelManager</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.managers.GenericModelManager" title="Permalink to this definition">¶</a></dt>
<dd><p>Manager with for_model method.</p>
<dl class="method">
<dt id="generic_utils.managers.GenericModelManager.for_model">
<tt class="descname">for_model</tt><big>(</big><em>model</em>, <em>content_type=None</em><big>)</big><a class="headerlink" href="#generic_utils.managers.GenericModelManager.for_model" title="Permalink to this definition">¶</a></dt>
<dd>Returns all objects that are attached to given model</dd></dl>

</dd></dl>

<dl class="class">
<dt id="generic_utils.managers.RelatedInjector">
<em class="property">
class </em><tt class="descclassname">generic_utils.managers.</tt><tt class="descname">RelatedInjector</tt><big>(</big><em>fk_field='object_id'</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.managers.RelatedInjector" title="Permalink to this definition">¶</a></dt>
<dd><p>Manager that can emulate <tt class="docutils literal"><span class="pre">select_related</span></tt> fetching
reverse relations using 1 additional SQL query.</p>
<dl class="method">
<dt id="generic_utils.managers.RelatedInjector.inject_to">
<tt class="descname">inject_to</tt><big>(</big><em>objects</em>, <em>field_name</em>, <em>get_inject_object=&lt;function &lt;lambda&gt; at 0x1a4a3f0&gt;</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#generic_utils.managers.RelatedInjector.inject_to" title="Permalink to this definition">¶</a></dt>
<dd><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">objects</span></tt> is an iterable. Related objects</dt>
<dd>will be attached to elements of this iterable.</dd>
</dl>
<p><tt class="docutils literal"><span class="pre">field_name</span></tt> is the attached object attribute name</p>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">get_injector_object</span></tt> is a callable that takes object in <cite>objects</cite></dt>
<dd>iterable. Related objects will be available as an attribute of the
result of <tt class="docutils literal"><span class="pre">get_inject_object(obj)</span></tt>. It is assumed that <tt class="docutils literal"><span class="pre">fk_field</span></tt>
points to  <tt class="docutils literal"><span class="pre">get_inject_object(obj)</span></tt>.</dd>
</dl>
<p>All other kwargs will be passed as arguments to queryset filter function.</p>
<p>For example, we need to prefetch user profiles when we display a list of
comments:</p>
<div class="highlight-python"><pre># models.py
class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    info = models.CharField(max_length=100)
    objects = models.Manager()
    injector = RelatedInjector(fk_field='user')

# views.py
def show_comments(request, obj_id):
    ...
    comments = list(Comment.objects.for_model(obj).select_related('user'))
    UserProfile.injector.inject_to(comments, '_profile_cache',
                                   lambda comment: comment.user)

    return direct_to_template('comment_list.html', {'comments': comments})

# in comment_list.html
{% for comment in comments %}
    &lt;h3&gt;{{ comment.user }}&lt;/h3&gt;
    &lt;h4&gt;{{ comment.user.get_profile.info }}&lt;/h4&gt;
    {{ comment.comment|linebreaks }}
{% endfor %}</pre>
</div>
<p><tt class="docutils literal"><span class="pre">comment.user</span></tt> attribute will be selected using <tt class="docutils literal"><span class="pre">select_related</span></tt> and
<tt class="docutils literal"><span class="pre">comment.user._profile_cache</span></tt> (exposed by get_profile method) will be
selected by our injector. So there will be only 2 SQL queries for
selecting all comments with users and user profiles.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-generic_utils.templatetags">
<h4>Template tag helpers<a class="headerlink" href="#module-generic_utils.templatetags" title="Permalink to this headline">¶</a></h4>
<dl class="exception">
<dt id="generic_utils.templatetags.InvalidParamsError">
<em class="property">
exception </em><tt class="descclassname">generic_utils.templatetags.</tt><tt class="descname">InvalidParamsError</tt><a class="headerlink" href="#generic_utils.templatetags.InvalidParamsError" title="Permalink to this definition">¶</a></dt>
<dd>Custom exception class to distinguish usual TemplateSyntaxErrors 
and validation errors for templatetags introduced by <tt class="docutils literal"><span class="pre">validate_params</span></tt>
function</dd></dl>

<dl class="function">
<dt id="generic_utils.templatetags.validate_params">
<tt class="descclassname">generic_utils.templatetags.</tt><tt class="descname">validate_params</tt><big>(</big><em>bits</em>, <em>arguments_count</em>, <em>keyword_positions</em><big>)</big><a class="headerlink" href="#generic_utils.templatetags.validate_params" title="Permalink to this definition">¶</a></dt>
<dd>Raises exception if passed params (<cite>bits</cite>) do not match signature.
Signature is defined by <cite>arguments_count</cite> (acceptible number of params) and
keyword_positions (dictionary with positions in keys and keywords in values,
for ex. {2:&#8217;by&#8217;, 4:&#8217;of&#8217;, 5:&#8217;type&#8217;, 7:&#8217;as&#8217;}).</dd></dl>

</div>
<div class="section" id="module-generic_utils.test_helpers">
<h4>Test helpers<a class="headerlink" href="#module-generic_utils.test_helpers" title="Permalink to this headline">¶</a></h4>
<dl class="class">
<dt id="generic_utils.test_helpers.ViewTest">
<em class="property">
class </em><tt class="descclassname">generic_utils.test_helpers.</tt><tt class="descname">ViewTest</tt><big>(</big><em>methodName='runTest'</em><big>)</big><a class="headerlink" href="#generic_utils.test_helpers.ViewTest" title="Permalink to this definition">¶</a></dt>
<dd><p>TestCase for view testing</p>
<dl class="method">
<dt id="generic_utils.test_helpers.ViewTest.check_login_required">
<tt class="descname">check_login_required</tt><big>(</big><em>url_name</em>, <em>kwargs=None</em>, <em>current_app=None</em><big>)</big><a class="headerlink" href="#generic_utils.test_helpers.ViewTest.check_login_required" title="Permalink to this definition">¶</a></dt>
<dd>Check if response is a redirect to login page (ignoring GET variables)</dd></dl>

<dl class="method">
<dt id="generic_utils.test_helpers.ViewTest.check_url">
<tt class="descname">check_url</tt><big>(</big><em>url_name</em>, <em>status=200</em>, <em>kwargs=None</em>, <em>current_app=None</em><big>)</big><a class="headerlink" href="#generic_utils.test_helpers.ViewTest.check_url" title="Permalink to this definition">¶</a></dt>
<dd>check_url a URL and require a specific status code before proceeding</dd></dl>

</dd></dl>

</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="">Table Of Contents</a></h3>
            <ul>
<li><a class="reference" href="">django-generic-images&#8217;s documentation</a><ul>
<li><a class="reference" href="#installation">Installation</a></li>
<li><a class="reference" href="#usage">Usage</a><ul>
<li><a class="reference" href="#generic-images">Generic Images</a><ul>
<li><a class="reference" href="#models">Models</a></li>
<li><a class="reference" href="#module-generic_images.admin">Admin</a></li>
<li><a class="reference" href="#module-generic_images.managers">Managers</a></li>
<li><a class="reference" href="#module-generic_images.forms">Forms</a></li>
<li><a class="reference" href="#module-generic_images.fields">Fields for denormalisation</a></li>
<li><a class="reference" href="#module-generic_images.context_processors">Context processors</a></li>
</ul>
</li>
<li><a class="reference" href="#generic-utils">Generic Utils</a><ul>
<li><a class="reference" href="#module-generic_utils.app_utils">Pluggable app utils</a></li>
<li><a class="reference" href="#id1">Models</a></li>
<li><a class="reference" href="#module-generic_utils.managers">Generic relation helpers</a></li>
<li><a class="reference" href="#module-generic_utils.templatetags">Template tag helpers</a></li>
<li><a class="reference" href="#module-generic_utils.test_helpers">Test helpers</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>Next topic</h4>
            <p class="topless"><a href="upgrade.html"
                                  title="next chapter">Upgrade notes</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/index.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="upgrade.html" title="Upgrade notes"
             >next</a> |</li>
        <li><a href="">django-generic-images v0.35 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Mikhail Korobov.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
    </div>
  </body>
</html>