djangosnippets.org: Latest snippets tagged with 'generic'https://djangosnippets.org/tags/generic/2018-01-25T00:20:22.201486-06:00Django Generic Paginator
2018-01-25T00:20:22.201486-06:00agusmakmunhttps://djangosnippets.org/snippets/10640/<p>Django Generic Paginator for <code>generic.ListView</code></p>
Freely redistributableReusable form template with generic view
2015-12-02T08:02:40.154798-06:00roldandvghttps://djangosnippets.org/snippets/10541/<p>If you require lots of forms in your project and do not want to be creating an extended template for each one I propose this solution.</p>
<p>Classes in the html correspond to bootstrap, you can work without them if you do not use bootstrap.</p>
Freely redistributableGeneric CSV export admin action factory with relationship spanning fields and labels, and many to many fields
2014-02-01T19:44:04.482375-06:00selimnairbhttps://djangosnippets.org/snippets/3022/<p>Based on <a href="https://djangosnippets.org/snippets/2868/">#2868</a></p>
<p>Now with support for writing the absolute URL of file fields</p>
Freely redistributableGeneric CSV export admin action factory with relationship spanning fields and labels
2012-12-21T15:41:10.986777-06:00blackrobothttps://djangosnippets.org/snippets/2868/<p>Based on <a href="../2712/">#2712</a></p>
<p>"This snippet creates a simple generic export to csv action that you can specify the fields you want exported and the labels used in the header row for each field. It expands on #2020 by using list comprehensions instead of sets so that you also control the …</p>
Freely redistributablePrefetch generic relations
2011-07-19T05:20:59.399568-05:00jpichttps://djangosnippets.org/snippets/2492/<p>See the function docstring.</p>
Freely redistributableModel merging function
2010-12-01T10:20:52.274178-06:00xaralishttps://djangosnippets.org/snippets/2283/<p>Generic function to merge model instances. Useful when you need to merge duplicate models together, e.g. for users.</p>
<p>Based on http://djangosnippets.org/snippets/382/, with several enhancements:</p>
<ul>
<li><em>Type checking</em>: only Model subclasses can be used and testing that all instances are of same model class</li>
<li><em>Handles symmetrical many-to-may</em>: original snippet failed …</li></ul>
Freely redistributableintegrated jinja2 which could use generic view ,my djangojinja2.py
2009-12-29T13:08:30.036099-06:00jasongreenhttps://djangosnippets.org/snippets/1844/<p>I tried a few snippets of integrated jinja2 in django, which provided ?.render_to_string and ?.render_to_response in the way of jinja2. <strong>But those snippets could not use the generic view</strong>, because of the generic views is use default django template. so i write this snippet which could use generic view, …</p>
Freely redistributableImproved generic foreign key manager 2
2009-10-25T16:16:18.154445-05:00Nomalzhttps://djangosnippets.org/snippets/1773/<p>This is an improvement on <a href="http://www.djangosnippets.org/snippets/1079/">snippet 1079</a>. Please read its description and <a href="http://zerokspot.com/weblog/2008/08/13/genericforeignkeys-with-less-queries/">this blog post</a> for any information.
</p>
<p>This is a manager for handling generic foreign key. Generic foreign objects of the same type are fetched together in order to reduce the number of SQL queries.
</p>
<p>To use, just …</p>
Freely redistributabledjango redirects middleware a bit more fleixble
2009-10-23T10:19:22.123324-05:00robertrvhttps://djangosnippets.org/snippets/1770/<p>This is replace for django.contrib.redirects.RedirectFallbackMiddleware which redirects exact matches as well as startswith matches for the redirect.old_path</p>
<p>I had a problem with my urls, because are dynamically generic, so I can't create one redirect entry on the database for each possible url. So I made django redirects to search any …</p>
Freely redistributableURL models
2009-10-09T18:11:07.721923-05:00divermanhttps://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 redistributableGeneric view 'redirect_to' that supports QUERY_STRING
2009-10-06T11:17:29.607698-05:00marinhohttps://djangosnippets.org/snippets/1752/<p>This generic view does the same that 'django.views.generic.simple.redirect_to' does but supports request.GET parameters.</p>
Freely redistributableGeneric csv export admin action
2009-08-25T06:42:59.137380-05:00dekhttps://djangosnippets.org/snippets/1697/<p>A generic admin action to export selected objects as csv file. The csv file contains a first line with header information build from the models field names followed by the actual data rows.</p>
<p>Access is limited to staff users.</p>
<p>Requires django-1.1.</p>
<p><strong>Usage:</strong></p>
<p>Add the code to your project, e.g. a …</p>
Freely redistributableContent Moderator
2009-05-03T06:17:53.256842-05:00mutazmqhttps://djangosnippets.org/snippets/1479/<p>This snippet is for <a href="http://code.google.com/p/django-flag/">django-flag</a> Pinax app to make it generic moderator for any content model. You don't need to modify neither your model nor your views to moderate your flagged content objects.</p>
Freely redistributableCheap direct_to_tempalte patterns
2008-11-14T16:47:28.117951-06:00jjdelchttps://djangosnippets.org/snippets/1190/<p>Django cheap-pages</p>
<p>Methods to use when you just want to use the Django dispatcher and there will be no extra business logic in your pages.</p>
<p>In some cases flatpages is too flat, and store templates in DB is too much hassle</p>
<pre><code> >>> url(^name/$,
... direct_to_template,
... {'template': 'name.html'},
... name='name') …</code></pre>
Freely redistributableajax_validator generic view
2008-10-14T02:00:10.890020-05:00amituhttps://djangosnippets.org/snippets/1136/<p>Sample jQuery javascript to use this view:</p>
<pre><code>$(function(){
$("#id_username, #id_password, #id_password2, #id_email").blur(function(){
var url = "/ajax/validate-registration-form/?field=" + this.name;
var field = this.name;
$.ajax({
url: url, data: $("#registration_form").serialize(),
type: "post", dataType: "json",
success: function (response){
if(response.valid)
{
$("#"+field+"_errors").html("Sounds good");
}
else
{
$("#"+field+"_errors").html(response.errors);
}
}
});
});
});
</code></pre>
<p>For each field …</p>
Freely redistributable