Snippet List
The template creation script referenced [here] (http://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#ubuntudebian) doesn't work on Ubuntu Lucid, where the default PostgreSQL version is now 8.4 and some things have been moved around. I've edited the script to work on Ubuntu Lucid.
Consider following models:
class Product(models.Model):
code = modeld.CharField()
class ProductTrans(models.Model):
product = models.ForeignKey('Product')
language = models.ChoiceField(choices=settings.LANGUAGES)
title = models.ChaField()
description = models.ChaField()
With this snippet is possible search through all translations of product at the same time (using string concatenation in trigger):
Product.objects.extra(
where = ['product_product.fulltext @@ to_tsquery(%s)'],
params = [ 'someproduct' ]
)
For PostgreSQL >=8.4 only.
- sql
- models
- translations
- model
- full-text
- postgres
- postgresql
- language
- fulltext
- translation
i use this to get the pk of a record before creation,
in my scenario to name an uploaded image:
def UPLOADTO( i,n ):
if not i.id:
id = get_nextautoincrement( i.__class__ )
else:
id = i.id
return str(id)+'.jpg'
While django provides the `django_admin.py cleanup` script, if sessions get out of control sometimes you have to go lower level to get everything cleaned up. If the problem gets out of hand and you hit the resource limits of the machine, it is very difficult to get anything done in the database.
Attached is SQL code which was used to cleanup 27GB of expired session data in 3h. Run it like this to make sure it runs to completion:
`nohup mysql --user=username --password=password --host=hostname database < delete_expired_sessions.sql`
nohup causes the script to run detached from a terminal, so if your session gets disconnected it will keep running.
- mysql
- django.contrib.session
- expire
- innodb
11 snippets posted so far.