mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
remove name uniqueness, with migration
Signed-off-by: Jannis Leidel <jannis@leidel.info>
This commit is contained in:
parent
4507b02ed5
commit
e694b3dfb8
7 changed files with 100 additions and 3 deletions
|
|
@ -34,7 +34,7 @@ def load_template_source(template_name, template_dirs=None, annoy=True):
|
|||
except:
|
||||
pass
|
||||
try:
|
||||
template = Template.on_site.get(name__exact=template_name)
|
||||
template = Template.on_site.filter(name__exact=template_name)[0]
|
||||
# Save in cache backend explicitly if manually deleted or invalidated
|
||||
if cache:
|
||||
cache.set(cache_key, template.content)
|
||||
|
|
|
|||
57
dbtemplates/migrations/0001_initial.py
Normal file
57
dbtemplates/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# encoding: utf-8
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
|
||||
# Adding model 'Template'
|
||||
db.create_table('django_template', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=100)),
|
||||
('content', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||
('creation_date', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
|
||||
('last_changed', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
|
||||
))
|
||||
db.send_create_signal('dbtemplates', ['Template'])
|
||||
|
||||
# Adding M2M table for field sites on 'Template'
|
||||
db.create_table('django_template_sites', (
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
|
||||
('template', models.ForeignKey(orm['dbtemplates.template'], null=False)),
|
||||
('site', models.ForeignKey(orm['sites.site'], null=False))
|
||||
))
|
||||
db.create_unique('django_template_sites', ['template_id', 'site_id'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Deleting model 'Template'
|
||||
db.delete_table('django_template')
|
||||
|
||||
# Removing M2M table for field sites on 'Template'
|
||||
db.delete_table('django_template_sites')
|
||||
|
||||
|
||||
models = {
|
||||
'dbtemplates.template': {
|
||||
'Meta': {'ordering': "('name',)", 'object_name': 'Template', 'db_table': "'django_template'"},
|
||||
'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_changed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
|
||||
'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'})
|
||||
},
|
||||
'sites.site': {
|
||||
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
|
||||
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['dbtemplates']
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
# encoding: utf-8
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
|
||||
# Removing unique constraint on 'Template', fields ['name']
|
||||
db.delete_unique('django_template', ['name'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Adding unique constraint on 'Template', fields ['name']
|
||||
db.create_unique('django_template', ['name'])
|
||||
|
||||
|
||||
models = {
|
||||
'dbtemplates.template': {
|
||||
'Meta': {'ordering': "('name',)", 'object_name': 'Template', 'db_table': "'django_template'"},
|
||||
'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_changed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'})
|
||||
},
|
||||
'sites.site': {
|
||||
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
|
||||
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['dbtemplates']
|
||||
0
dbtemplates/migrations/__init__.py
Normal file
0
dbtemplates/migrations/__init__.py
Normal file
|
|
@ -19,7 +19,7 @@ class Template(models.Model):
|
|||
Defines a template model for use with the database template loader.
|
||||
The field ``name`` is the equivalent to the filename of a static template.
|
||||
"""
|
||||
name = models.CharField(_('name'), unique=True, max_length=100,
|
||||
name = models.CharField(_('name'), max_length=100,
|
||||
help_text=_("Example: 'flatpages/default.html'"))
|
||||
content = models.TextField(_('content'), blank=True)
|
||||
sites = models.ManyToManyField(Site, verbose_name=_('sites'))
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
django-staticfiles
|
||||
django-staticfiles
south
|
||||
|
|
@ -99,6 +99,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.admin',
|
||||
'django.contrib.flatpages',
|
||||
'dbtemplates',
|
||||
'south',
|
||||
'staticfiles',
|
||||
#'reversion',
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue