This file is indexed.

/usr/share/doc/python-django-modeltranslation/html/admin.html is in python-django-modeltranslation-doc 0.12.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!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 Admin Integration &#8212; django-modeltranslation 0.12.2 documentation</title>
    <link rel="stylesheet" href="_static/classic.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.12.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Management Commands" href="commands.html" />
    <link rel="prev" title="ModelForms" href="forms.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="commands.html" title="Management Commands"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="forms.html" title="ModelForms"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">django-modeltranslation 0.12.2 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="django-admin-integration">
<span id="admin"></span><h1>Django Admin Integration<a class="headerlink" href="#django-admin-integration" title="Permalink to this headline"></a></h1>
<p>In order to be able to edit the translations via the <code class="docutils literal"><span class="pre">django.contrib.admin</span></code>
application you need to register a special admin class for the translated
models. The admin class must derive from
<code class="docutils literal"><span class="pre">modeltranslation.admin.TranslationAdmin</span></code> which does some funky
patching on all your models registered for translation. Taken the
<a class="reference internal" href="registration.html#registration"><span class="std std-ref">news example</span></a> the most simple case would look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span></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">news.models</span> <span class="kn">import</span> <span class="n">News</span>
<span class="kn">from</span> <span class="nn">modeltranslation.admin</span> <span class="kn">import</span> <span class="n">TranslationAdmin</span>

<span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="k">pass</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">News</span><span class="p">,</span> <span class="n">NewsAdmin</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="tweaks-applied-to-the-admin">
<h2>Tweaks Applied to the Admin<a class="headerlink" href="#tweaks-applied-to-the-admin" title="Permalink to this headline"></a></h2>
<div class="section" id="formfield-for-dbfield">
<h3>formfield_for_dbfield<a class="headerlink" href="#formfield-for-dbfield" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal"><span class="pre">TranslationBaseModelAdmin</span></code> class, which <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> and all
inline related classes in modeltranslation derive from, implements a special
method which is <code class="docutils literal"><span class="pre">formfield_for_dbfield(self,</span> <span class="pre">db_field,</span> <span class="pre">**kwargs)</span></code>. This
method does the following:</p>
<ol class="arabic simple">
<li>Copies the widget of the original field to each of its translation fields.</li>
<li>Checks if the original field was required and if so makes the default
translation field required instead.</li>
</ol>
</div>
<div class="section" id="get-form-get-fieldsets-declared-fieldsets">
<h3>get_form/get_fieldsets/_declared_fieldsets<a class="headerlink" href="#get-form-get-fieldsets-declared-fieldsets" title="Permalink to this headline"></a></h3>
<p>In addition the <code class="docutils literal"><span class="pre">TranslationBaseModelAdmin</span></code> class overrides <code class="docutils literal"><span class="pre">get_form</span></code>,
<code class="docutils literal"><span class="pre">get_fieldsets</span></code> and <code class="docutils literal"><span class="pre">_declared_fieldsets</span></code> to make the options <code class="docutils literal"><span class="pre">fields</span></code>,
<code class="docutils literal"><span class="pre">exclude</span></code> and <code class="docutils literal"><span class="pre">fieldsets</span></code> work in a transparent way. It basically does:</p>
<ol class="arabic simple">
<li>Removes the original field from every admin form by adding it to
<code class="docutils literal"><span class="pre">exclude</span></code> under the hood.</li>
<li>Replaces the - now removed - orginal fields with their corresponding
translation fields.</li>
</ol>
<p>Taken the <code class="docutils literal"><span class="pre">fieldsets</span></code> option as an example, where the <code class="docutils literal"><span class="pre">title</span></code> field is
registered for translation but not the <code class="docutils literal"><span class="pre">news</span></code> field:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="n">fieldsets</span> <span class="o">=</span> <span class="p">[</span>
        <span class="p">(</span><span class="sa">u</span><span class="s1">&#39;News&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;title&#39;</span><span class="p">,</span> <span class="s1">&#39;news&#39;</span><span class="p">,)})</span>
    <span class="p">]</span>
</pre></div>
</div>
<p>In this case <code class="docutils literal"><span class="pre">get_fieldsets</span></code> will return a patched fieldset which contains
the translation fields of <code class="docutils literal"><span class="pre">title</span></code>, but not the original field:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">NewsAdmin</span><span class="p">(</span><span class="n">NewsModel</span><span class="p">,</span> <span class="n">site</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="o">.</span><span class="n">get_fieldsets</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
<span class="go">[(u&#39;News&#39;, {&#39;fields&#39;: (&#39;title_de&#39;, &#39;title_en&#39;, &#39;news&#39;,)})]</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="translationadmin-in-combination-with-other-admin-classes">
<span id="id1"></span><h2>TranslationAdmin in Combination with Other Admin Classes<a class="headerlink" href="#translationadmin-in-combination-with-other-admin-classes" title="Permalink to this headline"></a></h2>
<p>If there already exists a custom admin class for a translated model and you
don’t want or can’t edit that class directly there is another solution.</p>
<p>Taken a reusable blog app which defines a model <code class="docutils literal"><span class="pre">Entry</span></code> and a
corresponding admin class called <code class="docutils literal"><span class="pre">EntryAdmin</span></code>. This app is not yours and you
don’t want to touch it at all.</p>
<p>In the most common case you simply make use of Python’s support for multiple
inheritance like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyTranslatedEntryAdmin</span><span class="p">(</span><span class="n">EntryAdmin</span><span class="p">,</span> <span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="k">pass</span>
</pre></div>
</div>
<p>The class is then registered for the <code class="docutils literal"><span class="pre">admin.site</span></code> (not to be confused with
modeltranslation’s <code class="docutils literal"><span class="pre">translator</span></code>). If <code class="docutils literal"><span class="pre">EntryAdmin</span></code> is already registered
through the blog app, it has to be unregistered first:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">Entry</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">Entry</span><span class="p">,</span> <span class="n">MyTranslatedEntryAdmin</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="admin-classes-that-override-formfield-for-dbfield">
<h3>Admin Classes that Override <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code><a class="headerlink" href="#admin-classes-that-override-formfield-for-dbfield" title="Permalink to this headline"></a></h3>
<p>In a more complex setup the original <code class="docutils literal"><span class="pre">EntryAdmin</span></code> might override
<code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code> itself:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">EntryAdmin</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">Admin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">formfield_for_dbfield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c1"># does some funky stuff with the formfield here</span>
</pre></div>
</div>
<p>Unfortunately the first example won’t work anymore because Python can only
execute one of the <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code> methods. Since both admin classes
implement this method Python must make a decision and it chooses the first
class <code class="docutils literal"><span class="pre">EntryAdmin</span></code>. The functionality from <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> will not be
executed and translation in the admin will not work for this class.</p>
<p>But don’t panic, here’s a solution:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyTranslatedEntryAdmin</span><span class="p">(</span><span class="n">EntryAdmin</span><span class="p">,</span> <span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">formfield_for_dbfield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">field</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyTranslatedEntryAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">formfield_for_dbfield</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">patch_translation_field</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="n">field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">field</span>
</pre></div>
</div>
<p>This implements the <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code> such that both functionalities
will be executed. The first line calls the superclass method which in this case
will be the one of <code class="docutils literal"><span class="pre">EntryAdmin</span></code> because it is the first class inherited from.
The <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> capsulates its functionality in the
<code class="docutils literal"><span class="pre">patch_translation_field</span></code> method and the <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code>
implementation of the <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> class simply calls it. You can copy
this behaviour by calling it from a custom admin class and that’s done in the
example above. After that the <code class="docutils literal"><span class="pre">field</span></code> is fully patched for translation and
finally returned.</p>
</div>
</div>
<div class="section" id="admin-inlines">
<h2>Admin Inlines<a class="headerlink" href="#admin-inlines" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.2.</span></p>
</div>
<p>Support for tabular and stacked inlines, common and generic ones.</p>
<p>A translated inline must derive from one of the following classes:</p>
<blockquote>
<div><ul class="simple">
<li><code class="docutils literal"><span class="pre">modeltranslation.admin.TranslationTabularInline</span></code></li>
<li><code class="docutils literal"><span class="pre">modeltranslation.admin.TranslationStackedInline</span></code></li>
<li><code class="docutils literal"><span class="pre">modeltranslation.admin.TranslationGenericTabularInline</span></code></li>
<li><code class="docutils literal"><span class="pre">modeltranslation.admin.TranslationGenericStackedInline</span></code></li>
</ul>
</div></blockquote>
<p>Just like <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> these classes implement a special method
<code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code> which does all the patching.</p>
<p>For our example we assume that there is a new model called <code class="docutils literal"><span class="pre">Image</span></code>. The
definition is left out for simplicity. Our <code class="docutils literal"><span class="pre">News</span></code> model inlines the new
model:</p>
<div class="highlight-python"><div class="highlight"><pre><span></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">news.models</span> <span class="kn">import</span> <span class="n">Image</span><span class="p">,</span> <span class="n">News</span>
<span class="kn">from</span> <span class="nn">modeltranslation.admin</span> <span class="kn">import</span> <span class="n">TranslationTabularInline</span>

<span class="k">class</span> <span class="nc">ImageInline</span><span class="p">(</span><span class="n">TranslationTabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Image</span>

<span class="k">class</span> <span class="nc">NewsAdmin</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">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;title&#39;</span><span class="p">,)</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">ImageInline</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">News</span><span class="p">,</span> <span class="n">NewsAdmin</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In this example only the <code class="docutils literal"><span class="pre">Image</span></code> model is registered in
<code class="docutils literal"><span class="pre">translation.py</span></code>. It’s not a requirement that <code class="docutils literal"><span class="pre">NewsAdmin</span></code> derives from
<code class="docutils literal"><span class="pre">TranslationAdmin</span></code> in order to inline a model which is registered for
translation.</p>
</div>
<div class="section" id="complex-example-with-admin-inlines">
<h3>Complex Example with Admin Inlines<a class="headerlink" href="#complex-example-with-admin-inlines" title="Permalink to this headline"></a></h3>
<p>In this more complex example we assume that the <code class="docutils literal"><span class="pre">News</span></code> and <code class="docutils literal"><span class="pre">Image</span></code> models
are registered in <code class="docutils literal"><span class="pre">translation.py</span></code>. The <code class="docutils literal"><span class="pre">News</span></code> model has an own custom
admin class called <code class="docutils literal"><span class="pre">NewsAdmin</span></code> and the <code class="docutils literal"><span class="pre">Image</span></code> model an own generic stacked
inline class called <code class="docutils literal"><span class="pre">ImageInline</span></code>. Furthermore we assume that <code class="docutils literal"><span class="pre">NewsAdmin</span></code>
overrides <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code> itself and the admin class is already
registered through the news app.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The example uses the technique described in
<a class="reference internal" href="#translationadmin-in-combination-with-other-admin-classes">TranslationAdmin in combination with other admin classes</a>.</p>
</div>
<p>Bringing it all together our code might look like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></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">news.admin</span> <span class="kn">import</span> <span class="n">ImageInline</span>
<span class="kn">from</span> <span class="nn">news.models</span> <span class="kn">import</span> <span class="n">Image</span><span class="p">,</span> <span class="n">News</span>
<span class="kn">from</span> <span class="nn">modeltranslation.admin</span> <span class="kn">import</span> <span class="n">TranslationAdmin</span><span class="p">,</span> <span class="n">TranslationGenericStackedInline</span>

<span class="k">class</span> <span class="nc">TranslatedImageInline</span><span class="p">(</span><span class="n">ImageInline</span><span class="p">,</span> <span class="n">TranslationGenericStackedInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Image</span>

<span class="k">class</span> <span class="nc">TranslatedNewsAdmin</span><span class="p">(</span><span class="n">NewsAdmin</span><span class="p">,</span> <span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">TranslatedImageInline</span><span class="p">,]</span>

    <span class="k">def</span> <span class="nf">formfield_for_dbfield</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">field</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">TranslatedNewsAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">formfield_for_dbfield</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">patch_translation_field</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="n">field</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">field</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">unregister</span><span class="p">(</span><span class="n">News</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">News</span><span class="p">,</span> <span class="n">NewsAdmin</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="using-tabbed-translation-fields">
<h2>Using Tabbed Translation Fields<a class="headerlink" href="#using-tabbed-translation-fields" title="Permalink to this headline"></a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.3.</span></p>
</div>
<p>Modeltranslation supports separation of translation fields via jquery-ui tabs.
The proposed way to include it is through the inner <code class="docutils literal"><span class="pre">Media</span></code> class of a
<code class="docutils literal"><span class="pre">TranslationAdmin</span></code> class like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Media</span><span class="p">:</span>
        <span class="n">js</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s1">&#39;modeltranslation/js/force_jquery.js&#39;</span><span class="p">,</span>
            <span class="s1">&#39;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js&#39;</span><span class="p">,</span>
            <span class="s1">&#39;modeltranslation/js/tabbed_translation_fields.js&#39;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">css</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;screen&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;modeltranslation/css/tabbed_translation_fields.css&#39;</span><span class="p">,),</span>
        <span class="p">}</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Here we stick to the jquery library shipped with Django. The
<code class="docutils literal"><span class="pre">force_jquery.js</span></code> script is necessary when using Django’s built-in
<code class="docutils literal"><span class="pre">django.jQuery</span></code> object. Otherwise the <em>normal</em> <code class="docutils literal"><span class="pre">jQuery</span></code> object won’t
be available to the included (non-namespaced) jquery-ui library.</p>
</div>
<p>Standard jquery-ui theming can be used to customize the look of tabs, the
provided css file is supposed to work well with a default Django admin.</p>
<p>As an alternative, if want to use a more recent version of jquery, you can do so
by including this in your <code class="docutils literal"><span class="pre">Media</span></code> class instead:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Media</span><span class="p">:</span>
        <span class="n">js</span> <span class="o">=</span> <span class="p">(</span>
            <span class="s1">&#39;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#39;</span><span class="p">,</span>
            <span class="s1">&#39;http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js&#39;</span><span class="p">,</span>
            <span class="s1">&#39;modeltranslation/js/tabbed_translation_fields.js&#39;</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="n">css</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;screen&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;modeltranslation/css/tabbed_translation_fields.css&#39;</span><span class="p">,),</span>
        <span class="p">}</span>
</pre></div>
</div>
<div class="section" id="tabbed-translation-fields-admin-classes">
<h3>Tabbed Translation Fields Admin Classes<a class="headerlink" href="#tabbed-translation-fields-admin-classes" title="Permalink to this headline"></a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
<p>To ease the inclusion of the required static files for tabbed translation
fields, the following admin classes are provided:</p>
<blockquote>
<div><ul class="simple">
<li><code class="docutils literal"><span class="pre">TabbedDjangoJqueryTranslationAdmin</span></code> (aliased to <code class="docutils literal"><span class="pre">TabbedTranslationAdmin</span></code>)</li>
<li><code class="docutils literal"><span class="pre">TabbedExternalJqueryTranslationAdmin</span></code></li>
</ul>
</div></blockquote>
<p>Rather than inheriting from <code class="docutils literal"><span class="pre">TranslationAdmin</span></code>, simply subclass one of these
classes like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TabbedTranslationAdmin</span><span class="p">):</span>
    <span class="k">pass</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="translationadmin-options">
<h2><code class="docutils literal"><span class="pre">TranslationAdmin</span></code> Options<a class="headerlink" href="#translationadmin-options" title="Permalink to this headline"></a></h2>
<div class="section" id="translationadmin-group-fieldsets">
<h3><code class="docutils literal"><span class="pre">TranslationAdmin.group_fieldsets</span></code><a class="headerlink" href="#translationadmin-group-fieldsets" title="Permalink to this headline"></a></h3>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.</span></p>
</div>
<p>When this option is activated untranslated and translation fields are grouped
into separate fieldsets. The first fieldset contains the untranslated fields,
followed by a fieldset for each translation field. The translation field
fieldsets use the original field’s <code class="docutils literal"><span class="pre">verbose_name</span></code> as a label.</p>
<p>Activating the option is a simple way to reduce the visual clutter one might
experience when mixing these different types of fields.</p>
<p>The <code class="docutils literal"><span class="pre">group_fieldsets</span></code> option expects a boolean. By default fields are not
grouped into fieldsets (<code class="docutils literal"><span class="pre">group_fieldsets</span> <span class="pre">=</span> <span class="pre">False</span></code>).</p>
<p>A few simple policies are applied:</p>
<blockquote>
<div><ul class="simple">
<li>A <code class="docutils literal"><span class="pre">fieldsets</span></code> option takes precedence over the <code class="docutils literal"><span class="pre">group_fieldsets</span></code> option.</li>
<li>Other default <code class="docutils literal"><span class="pre">ModelAdmin</span></code> options like <code class="docutils literal"><span class="pre">exclude</span></code> are respected.</li>
</ul>
</div></blockquote>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="n">group_fieldsets</span> <span class="o">=</span> <span class="bp">True</span>
</pre></div>
</div>
</div>
<div class="section" id="formfields-with-none-checkbox">
<span id="admin-formfield"></span><h3>Formfields with None-checkbox<a class="headerlink" href="#formfields-with-none-checkbox" title="Permalink to this headline"></a></h3>
<p>There is the special widget which allow to choose whether empty field value should be stores as
empty string or <code class="docutils literal"><span class="pre">None</span></code> (see <a class="reference internal" href="forms.html#forms-formfield-both"><span class="std std-ref">None-checkbox widget</span></a>).
In <code class="docutils literal"><span class="pre">TranslationAdmin</span></code> some fields can use this widget regardless of their <code class="docutils literal"><span class="pre">empty_values</span></code>
setting:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NewsAdmin</span><span class="p">(</span><span class="n">TranslationAdmin</span><span class="p">):</span>
    <span class="n">both_empty_values_fields</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;title&#39;</span><span class="p">,</span> <span class="s1">&#39;text&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django Admin Integration</a><ul>
<li><a class="reference internal" href="#tweaks-applied-to-the-admin">Tweaks Applied to the Admin</a><ul>
<li><a class="reference internal" href="#formfield-for-dbfield">formfield_for_dbfield</a></li>
<li><a class="reference internal" href="#get-form-get-fieldsets-declared-fieldsets">get_form/get_fieldsets/_declared_fieldsets</a></li>
</ul>
</li>
<li><a class="reference internal" href="#translationadmin-in-combination-with-other-admin-classes">TranslationAdmin in Combination with Other Admin Classes</a><ul>
<li><a class="reference internal" href="#admin-classes-that-override-formfield-for-dbfield">Admin Classes that Override <code class="docutils literal"><span class="pre">formfield_for_dbfield</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#admin-inlines">Admin Inlines</a><ul>
<li><a class="reference internal" href="#complex-example-with-admin-inlines">Complex Example with Admin Inlines</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-tabbed-translation-fields">Using Tabbed Translation Fields</a><ul>
<li><a class="reference internal" href="#tabbed-translation-fields-admin-classes">Tabbed Translation Fields Admin Classes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#translationadmin-options"><code class="docutils literal"><span class="pre">TranslationAdmin</span></code> Options</a><ul>
<li><a class="reference internal" href="#translationadmin-group-fieldsets"><code class="docutils literal"><span class="pre">TranslationAdmin.group_fieldsets</span></code></a></li>
<li><a class="reference internal" href="#formfields-with-none-checkbox">Formfields with None-checkbox</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="forms.html"
                        title="previous chapter">ModelForms</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="commands.html"
                        title="next chapter">Management Commands</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/admin.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="commands.html" title="Management Commands"
             >next</a> |</li>
        <li class="right" >
          <a href="forms.html" title="ModelForms"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">django-modeltranslation 0.12.2 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2009-2018, Peter Eschler, Dirk Eschler, Jacek Tomaszewski.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
    </div>
  </body>
</html>