From 4d9246f843b4f4a8decda8078283457ad4c378ee Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 9 Feb 2011 10:16:49 -0500 Subject: [PATCH] Added db_index to Contentlet/ContentReference names, AttributeValue fields, and Navigation keys. Added related_lookup_fields to shipherd admins and corrected its use on NodeAdmin/RedirectAdmin. Corrected TargetURLModel.get_target_url call of get_reverse_params. Corrected typo in BlogView feed creation. --- admin/nodes.py | 6 +- contrib/penfield/models.py | 2 +- contrib/shipherd/admin.py | 3 + contrib/shipherd/migrations/0002_auto.py | 75 +++++++++++ contrib/shipherd/models.py | 2 +- migrations/0014_auto.py | 156 +++++++++++++++++++++++ models/base.py | 8 +- models/nodes.py | 4 +- models/pages.py | 4 +- 9 files changed, 247 insertions(+), 13 deletions(-) create mode 100644 contrib/shipherd/migrations/0002_auto.py create mode 100644 migrations/0014_auto.py diff --git a/admin/nodes.py b/admin/nodes.py index fdfbc02..66be107 100644 --- a/admin/nodes.py +++ b/admin/nodes.py @@ -5,7 +5,7 @@ from philo.models import Node, Redirect, File class NodeAdmin(TreeEntityAdmin): list_display = ('slug', 'view', 'accepts_subpath') - related_field_lookups = { + related_lookup_fields = { 'fk': [], 'm2m': [], 'generic': [['view_content_type', 'view_object_id']] @@ -33,8 +33,8 @@ class RedirectAdmin(ViewAdmin): list_display = ('target_url', 'status_code', 'target_node', 'url_or_subpath') list_filter = ('status_code',) raw_id_fields = ['target_node'] - related_field_lookups = { - 'fk': ['target_node'] + related_lookup_fields = { + 'fk': raw_id_fields } diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py index a884663..bb71ba2 100644 --- a/contrib/penfield/models.py +++ b/contrib/penfield/models.py @@ -533,7 +533,7 @@ class BlogView(FeedView): item_context = { 'paginator': paginator, 'paginated_page': paginated_page, - self.item_context_var: objects + self.item_context_var: items } else: item_context = { diff --git a/contrib/shipherd/admin.py b/contrib/shipherd/admin.py index fb6cffe..93d21e5 100644 --- a/contrib/shipherd/admin.py +++ b/contrib/shipherd/admin.py @@ -12,6 +12,7 @@ class NavigationItemInline(admin.StackedInline): model = NavigationItem extra = 1 sortable_field_name = 'order' + related_lookup_fields = {'fk': raw_id_fields} class NavigationItemChildInline(NavigationItemInline): @@ -92,12 +93,14 @@ class NavigationItemAdmin(TreeEntityAdmin): }) ) raw_id_fields = NAVIGATION_RAW_ID_FIELDS + related_lookup_fields = {'fk': raw_id_fields} inlines = [NavigationItemChildInline] + TreeEntityAdmin.inlines class NavigationAdmin(EntityAdmin): inlines = [NavigationNavigationItemInline] raw_id_fields = ['node'] + related_lookup_fields = {'fk': raw_id_fields} admin.site.unregister(Node) diff --git a/contrib/shipherd/migrations/0002_auto.py b/contrib/shipherd/migrations/0002_auto.py new file mode 100644 index 0000000..00d095f --- /dev/null +++ b/contrib/shipherd/migrations/0002_auto.py @@ -0,0 +1,75 @@ +# 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 index on 'Navigation', fields ['key'] + db.create_index('shipherd_navigation', ['key']) + + + def backwards(self, orm): + + # Removing index on 'Navigation', fields ['key'] + db.delete_index('shipherd_navigation', ['key']) + + + models = { + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'philo.attribute': { + 'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'}, + 'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}), + 'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), + 'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + }, + 'philo.node': { + 'Meta': {'object_name': 'Node'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'node_view_set'", 'to': "orm['contenttypes.ContentType']"}), + 'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + 'shipherd.navigation': { + 'Meta': {'unique_together': "(('node', 'key'),)", 'object_name': 'Navigation'}, + 'depth': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '3'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'node': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'navigation_set'", 'to': "orm['philo.Node']"}) + }, + 'shipherd.navigationitem': { + 'Meta': {'object_name': 'NavigationItem'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'navigation': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'roots'", 'null': 'True', 'to': "orm['shipherd.Navigation']"}), + 'order': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['shipherd.NavigationItem']"}), + 'reversing_parameters': ('philo.models.fields.JSONField', [], {'blank': 'True'}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'target_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'shipherd_navigationitem_related'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'text': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'url_or_subpath': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}) + } + } + + complete_apps = ['shipherd'] diff --git a/contrib/shipherd/models.py b/contrib/shipherd/models.py index 2eacc89..8efc57a 100644 --- a/contrib/shipherd/models.py +++ b/contrib/shipherd/models.py @@ -169,7 +169,7 @@ class Navigation(Entity): objects = NavigationManager() node = models.ForeignKey(Node, related_name='navigation_set', help_text="Be available as navigation for this node.") - key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.") + key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.", db_index=True) depth = models.PositiveSmallIntegerField(default=DEFAULT_NAVIGATION_DEPTH, validators=[MinValueValidator(1)], help_text="Defines the maximum display depth of this navigation.") def __init__(self, *args, **kwargs): diff --git a/migrations/0014_auto.py b/migrations/0014_auto.py new file mode 100644 index 0000000..6375c69 --- /dev/null +++ b/migrations/0014_auto.py @@ -0,0 +1,156 @@ +# 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 index on 'Contentlet', fields ['name'] + db.create_index('philo_contentlet', ['name']) + + # Adding index on 'JSONValue', fields ['value'] + db.create_index('philo_jsonvalue', ['value_json']) + + # Adding index on 'ForeignKeyValue', fields ['object_id'] + db.create_index('philo_foreignkeyvalue', ['object_id']) + + # Adding index on 'ContentReference', fields ['name'] + db.create_index('philo_contentreference', ['name']) + + + def backwards(self, orm): + + # Removing index on 'ContentReference', fields ['name'] + db.delete_index('philo_contentreference', ['name']) + + # Removing index on 'ForeignKeyValue', fields ['object_id'] + db.delete_index('philo_foreignkeyvalue', ['object_id']) + + # Removing index on 'JSONValue', fields ['value'] + db.delete_index('philo_jsonvalue', ['value_json']) + + # Removing index on 'Contentlet', fields ['name'] + db.delete_index('philo_contentlet', ['name']) + + + models = { + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + 'philo.attribute': { + 'Meta': {'unique_together': "(('key', 'entity_content_type', 'entity_object_id'), ('value_content_type', 'value_object_id'))", 'object_name': 'Attribute'}, + 'entity_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'attribute_entity_set'", 'to': "orm['contenttypes.ContentType']"}), + 'entity_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'key': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'value_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'attribute_value_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), + 'value_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + }, + 'philo.collection': { + 'Meta': {'object_name': 'Collection'}, + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'philo.collectionmember': { + 'Meta': {'object_name': 'CollectionMember'}, + 'collection': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'members'", 'to': "orm['philo.Collection']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'member_content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'member_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + 'philo.contentlet': { + 'Meta': {'object_name': 'Contentlet'}, + 'content': ('philo.models.fields.TemplateField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentlets'", 'to': "orm['philo.Page']"}) + }, + 'philo.contentreference': { + 'Meta': {'object_name': 'ContentReference'}, + 'content_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentreferences'", 'to': "orm['philo.Page']"}) + }, + 'philo.file': { + 'Meta': {'object_name': 'File'}, + 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'mimetype': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'philo.foreignkeyvalue': { + 'Meta': {'object_name': 'ForeignKeyValue'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + }, + 'philo.jsonvalue': { + 'Meta': {'object_name': 'JSONValue'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'value': ('philo.models.fields.JSONField', [], {'default': "'null'", 'db_index': 'True'}) + }, + 'philo.manytomanyvalue': { + 'Meta': {'object_name': 'ManyToManyValue'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'values': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['philo.ForeignKeyValue']", 'null': 'True', 'blank': 'True'}) + }, + 'philo.node': { + 'Meta': {'object_name': 'Node'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'view_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'node_view_set'", 'to': "orm['contenttypes.ContentType']"}), + 'view_object_id': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + 'philo.page': { + 'Meta': {'object_name': 'Page'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'template': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'pages'", 'to': "orm['philo.Template']"}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + 'philo.redirect': { + 'Meta': {'object_name': 'Redirect'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'reversing_parameters': ('philo.models.fields.JSONField', [], {'blank': 'True'}), + 'status_code': ('django.db.models.fields.IntegerField', [], {'default': '302'}), + 'target_node': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'philo_redirect_related'", 'null': 'True', 'to': "orm['philo.Node']"}), + 'url_or_subpath': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}) + }, + 'philo.tag': { + 'Meta': {'ordering': "('name',)", 'object_name': 'Tag'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}) + }, + 'philo.template': { + 'Meta': {'object_name': 'Template'}, + 'code': ('philo.models.fields.TemplateField', [], {}), + 'documentation': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'mimetype': ('django.db.models.fields.CharField', [], {'default': "'text/html'", 'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['philo.Template']"}), + 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'db_index': 'True'}), + 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + } + } + + complete_apps = ['philo'] diff --git a/models/base.py b/models/base.py index 5f8fb03..8370bb7 100644 --- a/models/base.py +++ b/models/base.py @@ -81,7 +81,7 @@ attribute_value_limiter = ContentTypeSubclassLimiter(AttributeValue) class JSONValue(AttributeValue): - value = JSONField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.', default='null') + value = JSONField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.', default='null', db_index=True) def __unicode__(self): return smart_str(self.value) @@ -104,7 +104,7 @@ class JSONValue(AttributeValue): class ForeignKeyValue(AttributeValue): content_type = models.ForeignKey(ContentType, limit_choices_to=value_content_type_limiter, verbose_name='Value type', null=True, blank=True) - object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True) + object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True, db_index=True) value = generic.GenericForeignKey() def value_formfields(self): @@ -219,11 +219,11 @@ class ManyToManyValue(AttributeValue): class Attribute(models.Model): - entity_content_type = models.ForeignKey(ContentType, related_name='attribute_entity_set', verbose_name='Entity type', db_index=True) + entity_content_type = models.ForeignKey(ContentType, related_name='attribute_entity_set', verbose_name='Entity type') entity_object_id = models.PositiveIntegerField(verbose_name='Entity ID', db_index=True) entity = generic.GenericForeignKey('entity_content_type', 'entity_object_id') - value_content_type = models.ForeignKey(ContentType, related_name='attribute_value_set', limit_choices_to=attribute_value_limiter, verbose_name='Value type', null=True, blank=True, db_index=True) + value_content_type = models.ForeignKey(ContentType, related_name='attribute_value_set', limit_choices_to=attribute_value_limiter, verbose_name='Value type', null=True, blank=True) value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True, db_index=True) value = generic.GenericForeignKey('value_content_type', 'value_object_id') diff --git a/models/nodes.py b/models/nodes.py index 09376b8..10c51b4 100644 --- a/models/nodes.py +++ b/models/nodes.py @@ -234,7 +234,7 @@ class TargetURLModel(models.Model): node = self.target_node if node is not None and node.accepts_subpath and self.url_or_subpath: if self.reversing_parameters is not None: - view_name, args, kwargs = self.get_reversing_params() + view_name, args, kwargs = self.get_reverse_params() subpath = node.view.reverse(view_name, args=args, kwargs=kwargs) else: subpath = self.url_or_subpath @@ -245,7 +245,7 @@ class TargetURLModel(models.Model): return node.get_absolute_url() else: if self.reversing_parameters is not None: - view_name, args, kwargs = self.get_reversing_params() + view_name, args, kwargs = self.get_reverse_params() return reverse(view_name, args=args, kwargs=kwargs) return self.url_or_subpath target_url = property(get_target_url) diff --git a/models/pages.py b/models/pages.py index 81b84c9..ef68b5f 100644 --- a/models/pages.py +++ b/models/pages.py @@ -108,7 +108,7 @@ class Page(View): class Contentlet(models.Model): page = models.ForeignKey(Page, related_name='contentlets') - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, db_index=True) content = TemplateField() def __unicode__(self): @@ -120,7 +120,7 @@ class Contentlet(models.Model): class ContentReference(models.Model): page = models.ForeignKey(Page, related_name='contentreferences') - name = models.CharField(max_length=255) + name = models.CharField(max_length=255, db_index=True) content_type = models.ForeignKey(ContentType, verbose_name='Content type') content_id = models.PositiveIntegerField(verbose_name='Content ID', blank=True, null=True) content = generic.GenericForeignKey('content_type', 'content_id') -- 2.20.1