Django Number Input
This will give you a <input type='number'> field. This is helpful when you want to use HTML5 for newer browsers. Older browsers will just interpret this as <input type='text'>
- django
- django-forms
- input-types
This will give you a <input type='number'> field. This is helpful when you want to use HTML5 for newer browsers. Older browsers will just interpret this as <input type='text'>
The snippet enables decoupling model classes, associated with a ForeignKey, for the purpose of separating them into two databases. Looking at the following example: class Reporter(models.Model): ... class Article(models.Model): reporter = models.ForeignKey(Reporter) We want to separate the `Reporter` and `Article` into two separate databases, but this won't work in Django because of the [cross model relations](http://docs.djangoproject.com/en/dev/topics/db/multi-db/#cross-database-relations). The solution is to use an ID field and not a `ForeignKey` one. This makes the access very uncomfortable. The above class will make this a bit less awkward. It doesn't support the [RelatedManager](http://docs.djangoproject.com/en/dev/ref/models/relations/#django.db.models.fields.related.RelatedManager), but it will support accessing the related field as you normally would. The article class will look like this (assuming the reporter model id field is an `IntegerField`): class Article(DecoupledModel): reporter_id = models.IntegerField() _linked_fields = { 'reporter': Reporter, } Once you have an article object, you can access the reporter as you normally would for both read and writing. For example: my_reporter = article1.reporter article2.reporter = my_reporter
Riffing on http://djangosnippets.org/snippets/1024/ I didn't want a graph; I just wanted to see what depended on a specific model. This does that nicely.
Very much like the snippet joshua wrote (http://djangosnippets.org/snippets/67/) for the same purpose but with the addition that this lets the user get values for more complex settings like dicts and lists
Read code for info
**You can save these codes into a templatetag file in your django app. Then use codes like these in your template files:** **************************************************************************** {% load *yourtags* %} ... <img src="{% thumb *yourmodel.picturefield* 200 300 0 %}"/> <img src="{% thumb *yourmodel.picturefield* 500 400 yes %}"/> ... The parameters are: imagefield ImageField width Integer height Integer rescale [1, yes, true, 0, no, false] **Some codes come from <djangosnippets.org>**
This is an improvement of [joshua](http://djangosnippets.org/users/joshua/)'s [SQL Log Middleware](http://djangosnippets.org/snippets/61/). If you have more than one database connection, then all queries are logged, grouped by connection. If a connection has no queries, then it's not shown.
Small changes to [Snippet 1694](http://djangosnippets.org/snippets/1694/) to that QueryAPI works for django 1.2 and higher. Changes: * Replaced `get_db_prep_value` with `get_prep_value`. * Replaced `get_db_prep_lookup` with modified `get_prep_lookup`.
Adds filtering by ranges of dates in the admin filter sidebar. [https://github.com/coolchevy/django-datefilterspec](https://github.com/coolchevy/django-datefilterspec) [http://coolchevy.org.ua](http://coolchevy.org.ua) https://github.com/coolchevy/django-datefilterspec/raw/master/datefilter.png Example: ` from django.db import models import datefilterspec class Person(models.Model): date = models.DateTimeField(default=datetime.datetime.now) date.date_filter = True class Admin: list_filter = ['date']
serialize model object to dict with related objects
Three step list comprehension for getting a set of categories existing in a group of objects
Ah... the quick-and-dirty decorator for static navigation context, such a time-saver ;)
Takes the current DateTime and adds either days, hours, minutes, or seconds to the datetime object.
Method which gets a chunk of HTML to perform standard Google Analytics tracking as well as a noscript version. Very useful for finding out what percentage of your users do not have JavaScript support. This is Python port of the PHP example here: [http://andrescholten.net/google-analytics-zonder-javascript/](http://andrescholten.net/google-analytics-zonder-javascript/) To use, you need to put the following into your settings file: GOOGLE_ANALYTICS_ID = 'UA-1234567-1' GOOGLE_ANALYTICS_DOMAIN = 'example.com'
This is just a very thin layer of functionality for better readability. Does not have any effect on runtime performance.
2955 snippets posted so far.