djangosnippets.org: Latest snippets tagged with 'contenttypes'http://djangosnippets.org/tags/contenttypes/2018-01-14T21:42:58.502236-06:00Content type to get Model
2018-01-14T21:42:58.502236-06:00agusmakmunhttp://djangosnippets.org/snippets/10634/<p>Instance class model with <code>class ModelName(models.Model, ContentTypeToGetModel):</code></p>
Freely redistributableContentType template filter
2013-12-31T02:30:37.563758-06:00asfaltboyhttp://djangosnippets.org/snippets/3015/<p>Custom template filter to retrieve a content type of a given model instance. Useful for ModelForms which want to set the content_type field (i.e: GenericForeignKey).</p>
<h3>A usage example:</h3>
<pre><code>{% load helpers %}
{% with instance|content_type as ctype %}
<input type="hidden" name="content_type" value="{{ ctype.pk }}">
{% endwith %}
</code></pre>
<p>Original idea from …</p>
Freely redistributableFix for the bad behaviour of GenericForeignKey field
2011-01-03T14:16:03.933530-06:00pinkeenhttp://djangosnippets.org/snippets/2307/<p>I don't know if you noticed but GenericForeignKey behaves badly in some situations. Particularly if you assign a not yet saved object (without pk) to this field then you save this object the fk_field does not get updated (even upon saving the model)- it's updated only upon assigning object to …</p>
Freely redistributableURL models
2009-10-09T18:11:07.721923-05:00divermanhttp://djangosnippets.org/snippets/1755/<p>You can use <code>UrlModel</code> to provide URL functionality to any instance of any model and any language (language support can be removed from this). Each model must have own view method, that returns HttpResponse. I was inspired by Flatpages. It is useful for small sites and static pages.</p>
<pre><code>`class Page(UrlModel): …</code></pre>
Freely redistributableImportObject: Import model *instance* specific code at runtime
2009-08-13T02:00:02.772788-05:00guettlihttp://djangosnippets.org/snippets/1681/<p>See docstring</p>
Freely redistributableImproved model select field for generic relationships
2009-07-02T13:17:15.764272-05:00kratoriushttp://djangosnippets.org/snippets/1612/<p>Browse through the installed models using the content types framework.
There are two difference in behavior with respect to the default field:</p>
<ol>
<li>if a model provides a translation for its name (e.g.: verbose_name and/or verbose_name_plural), it shows that rather than a raw model name</li>
<li>allow to filter the models shown …</li></ol>
Freely redistributableUpdate ContentTypes and Permissions without syncdb
2008-04-11T10:54:34.543452-05:00paltmanhttp://djangosnippets.org/snippets/698/<p><a href="http://paltman.com/2008/04/11/keeping-contenttypes-and-permissions-updated-without-syncdb/">See blog post</a></p>
<p>You can put this script in the root of your project and run after deploying updates in your production environment.</p>
Freely redistributableUpdate ContentTypes and Permissions without syncdb
2008-04-11T10:54:04.304974-05:00paltmanhttp://djangosnippets.org/snippets/697/<p>http://paltman.com/2008/04/11/keeping-contenttypes-and-permissions-updated-without-syncdb/</p>
Freely redistributableUpdate ContentTypes and Permissions without syncdb
2008-04-11T10:53:40.816863-05:00paltmanhttp://djangosnippets.org/snippets/696/<p>http://paltman.com/2008/04/11/keeping-contenttypes-and-permissions-updated-without-syncdb/</p>
Freely redistributable