Commits

Kevin Veroneau committed d5fc239 Draft

Added basic models.py and admin.py file generation.

Comments (0)

Files changed (10)

django_helper/admin.py

 from django.contrib import admin
-from django_helper.models import TemplateTag, ContextProcessor, Middleware
+from django_helper.models import TemplateTag, ContextProcessor, Middleware, Model, FieldType, Field
+from django.conf.urls import patterns
+from django.shortcuts import render_to_response
 
 class TemplateTagAdmin(admin.ModelAdmin):
     list_filter = ('tag_type', 'app_name', 'takes_context', )
 admin.site.register(TemplateTag, TemplateTagAdmin)
 admin.site.register(ContextProcessor, ContextProcessorAdmin)
 admin.site.register(Middleware, MiddlewareAdmin)
+
+class FieldInline(admin.TabularInline):
+    model = Field
+    fk_name = 'model'
+    fields = ('name', 'field_type',)
+
+class ModelAdmin(admin.ModelAdmin):
+    inlines = [FieldInline]
+    filter_horizontal = ('exclude', 'fields', 'filter_horizontal', 'filter_vertical', 'list_display', 'list_filter', 'raw_id_fields', )
+    actions = ['export_models', 'export_admins']
+    fieldsets = (
+        (None, {
+            'fields': ('name', 'unicode', 'unicode_str', 'absolute_url', )
+        }),
+        ('ModelAdmin', {
+            'classes': ('collapse', ),
+            'fields': ('date_hierarchy', 'exclude', 'fields', 'filter_horizontal', 'filter_vertical', 'inlines', 'list_display', 'list_filter', 'raw_id_fields', )
+        }),
+    )
+    def get_urls(self):
+        urls = super(ModelAdmin, self).get_urls()
+        my_urls = patterns('',
+            (r'^(?P<object_id>\d+)/export/models.py$', self.admin_site.admin_view(self.export_model)),
+            (r'^(?P<object_id>\d+)/export/admin.py$', self.admin_site.admin_view(self.export_admin)),
+        )
+        return my_urls + urls
+    def export_model(self, req, object_id):
+        return render_to_response("admin/django_helper/model.txt", {'model':Model.objects.get(pk=object_id)}, mimetype='text/plain')
+    def export_admin(self, req, object_id):
+        return render_to_response("admin/django_helper/admin.txt", {'model':Model.objects.get(pk=object_id)}, mimetype='text/plain')
+    def export_models(self, req, queryset):
+        return render_to_response("admin/django_helper/models.txt", {'model_list':queryset}, mimetype='text/plain')
+    export_models.short_description = "Export selected to a models.py file"
+    def export_admins(self, req, queryset):
+        return render_to_response("admin/django_helper/admins.txt", {'model_list':queryset}, mimetype='text/plain')
+    export_admins.short_description = "Export selected to a admin.py file"
+
+class FieldTypeAdmin(admin.ModelAdmin):
+    list_filter = ('backend_storage',)
+    list_display = ('__unicode__', 'backend_storage', )
+
+class FieldAdmin(admin.ModelAdmin):
+    list_filter = ('model', 'field_type', )
+    list_display = ('__unicode__', 'model', 'field_type', )
+    fieldsets = (
+        (None, {
+            'fields': ('name', 'model', 'field_type')
+        }),
+        ('Field options', {
+            'classes': ('collapse', ),
+            'fields': ('null', 'blank', 'db_column', 'db_index', 'db_tablespace', 'default', 'editable', 'help_text', 'primary_key', 'unique', 'unique_for_date', 'unique_for_month', 'unique_for_year', 'verbose_name',)
+        }),
+        ('String options', {
+            'classes': ('collapse', ),
+            'fields': ('max_length', )
+        }),
+        ('DateTime options', {
+            'classes': ('collapse', ),
+            'fields': ('auto_now', 'auto_now_add', )
+        }),
+        ('Integer options', {
+            'classes': ('collapse', ),
+            'fields': ('max_digits', 'decimal_places', )
+        }),
+        ('Related field options', {
+            'classes': ('collapse', ),
+            'fields': ('othermodel', 'limit_choices_to', 'related_name', 'to_field', 'on_delete', 'through', 'db_table', )
+        }),
+        ('Other options', {
+            'classes': ('collapse', ),
+            'fields': ('upload_to', )
+        }),
+    )
+
+admin.site.register(Model, ModelAdmin)
+admin.site.register(FieldType, FieldTypeAdmin)
+admin.site.register(Field, FieldAdmin)

django_helper/migrations/0003_auto__chg_field_field_max_digits__chg_field_field_decimal_places.py

+# -*- coding: 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):
+
+        # Changing field 'Field.max_digits'
+        db.alter_column('django_helper_field', 'max_digits', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+        # Changing field 'Field.decimal_places'
+        db.alter_column('django_helper_field', 'decimal_places', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+    def backwards(self, orm):
+
+        # User chose to not deal with backwards NULL issues for 'Field.max_digits'
+        raise RuntimeError("Cannot reverse this migration. 'Field.max_digits' and its values cannot be restored.")
+
+        # User chose to not deal with backwards NULL issues for 'Field.decimal_places'
+        raise RuntimeError("Cannot reverse this migration. 'Field.decimal_places' and its values cannot be restored.")
+
+    models = {
+        'django_helper.contextprocessor': {
+            'Meta': {'object_name': 'ContextProcessor'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'required_middleware': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.Middleware']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'django_helper.field': {
+            'Meta': {'object_name': 'Field'},
+            'auto_now': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'auto_now_add': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'blank': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_column': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_index': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_table': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_tablespace': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'decimal_places': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'default': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'editable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'field_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.FieldType']"}),
+            'help_text': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'limit_choices_to': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'max_digits': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'max_length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'model': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.Model']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'null': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'on_delete': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'othermodel': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'othermodel_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'primary_key': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'related_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'through': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'through_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'to_field': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'foreign_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'unique_for_date': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'date_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_month': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'month_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_year': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'year_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'upload_to': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'verbose_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'})
+        },
+        'django_helper.fieldtype': {
+            'Meta': {'object_name': 'FieldType'},
+            'backend_storage': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'django_helper.middleware': {
+            'Meta': {'object_name': 'Middleware'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'process_exception': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_request': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_template_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        'django_helper.model': {
+            'Meta': {'object_name': 'Model'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'django_helper.templatetag': {
+            'Meta': {'object_name': 'TemplateTag'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'examples': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'parameters': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
+            'required_context': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.ContextProcessor']", 'symmetrical': 'False', 'blank': 'True'}),
+            'tag_name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tag_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'takes_context': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'template': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['django_helper']

django_helper/migrations/0004_auto__add_field_model_unicode__add_field_model_unicode_str__add_field_.py

+# -*- coding: 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 field 'Model.unicode'
+        db.add_column('django_helper_model', 'unicode',
+                      self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='unicode_set', null=True, to=orm['django_helper.Field']),
+                      keep_default=False)
+
+        # Adding field 'Model.unicode_str'
+        db.add_column('django_helper_model', 'unicode_str',
+                      self.gf('django.db.models.fields.CharField')(default='', max_length=80, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Model.absolute_url'
+        db.add_column('django_helper_model', 'absolute_url',
+                      self.gf('django.db.models.fields.CharField')(default='', max_length=80, blank=True),
+                      keep_default=False)
+
+        # Adding field 'Model.date_hierarchy'
+        db.add_column('django_helper_model', 'date_hierarchy',
+                      self.gf('django.db.models.fields.BooleanField')(default=False),
+                      keep_default=False)
+
+        # Adding field 'Model.inlines'
+        db.add_column('django_helper_model', 'inlines',
+                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['django_helper.Model'], null=True, blank=True),
+                      keep_default=False)
+
+        # Adding M2M table for field exclude on 'Model'
+        db.create_table('django_helper_model_exclude', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_exclude', ['model_id', 'field_id'])
+
+        # Adding M2M table for field fields on 'Model'
+        db.create_table('django_helper_model_fields', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_fields', ['model_id', 'field_id'])
+
+        # Adding M2M table for field filter_horizontal on 'Model'
+        db.create_table('django_helper_model_filter_horizontal', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_filter_horizontal', ['model_id', 'field_id'])
+
+        # Adding M2M table for field filter_vertical on 'Model'
+        db.create_table('django_helper_model_filter_vertical', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_filter_vertical', ['model_id', 'field_id'])
+
+        # Adding M2M table for field list_display on 'Model'
+        db.create_table('django_helper_model_list_display', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_list_display', ['model_id', 'field_id'])
+
+        # Adding M2M table for field list_filter on 'Model'
+        db.create_table('django_helper_model_list_filter', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_list_filter', ['model_id', 'field_id'])
+
+        # Adding M2M table for field raw_id_fields on 'Model'
+        db.create_table('django_helper_model_raw_id_fields', (
+            ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+            ('model', models.ForeignKey(orm['django_helper.model'], null=False)),
+            ('field', models.ForeignKey(orm['django_helper.field'], null=False))
+        ))
+        db.create_unique('django_helper_model_raw_id_fields', ['model_id', 'field_id'])
+
+
+    def backwards(self, orm):
+        # Deleting field 'Model.unicode'
+        db.delete_column('django_helper_model', 'unicode_id')
+
+        # Deleting field 'Model.unicode_str'
+        db.delete_column('django_helper_model', 'unicode_str')
+
+        # Deleting field 'Model.absolute_url'
+        db.delete_column('django_helper_model', 'absolute_url')
+
+        # Deleting field 'Model.date_hierarchy'
+        db.delete_column('django_helper_model', 'date_hierarchy')
+
+        # Deleting field 'Model.inlines'
+        db.delete_column('django_helper_model', 'inlines_id')
+
+        # Removing M2M table for field exclude on 'Model'
+        db.delete_table('django_helper_model_exclude')
+
+        # Removing M2M table for field fields on 'Model'
+        db.delete_table('django_helper_model_fields')
+
+        # Removing M2M table for field filter_horizontal on 'Model'
+        db.delete_table('django_helper_model_filter_horizontal')
+
+        # Removing M2M table for field filter_vertical on 'Model'
+        db.delete_table('django_helper_model_filter_vertical')
+
+        # Removing M2M table for field list_display on 'Model'
+        db.delete_table('django_helper_model_list_display')
+
+        # Removing M2M table for field list_filter on 'Model'
+        db.delete_table('django_helper_model_list_filter')
+
+        # Removing M2M table for field raw_id_fields on 'Model'
+        db.delete_table('django_helper_model_raw_id_fields')
+
+
+    models = {
+        'django_helper.contextprocessor': {
+            'Meta': {'object_name': 'ContextProcessor'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'required_middleware': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.Middleware']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'django_helper.field': {
+            'Meta': {'object_name': 'Field'},
+            'auto_now': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'auto_now_add': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'blank': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_column': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_index': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_table': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_tablespace': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'decimal_places': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'default': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'editable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'field_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.FieldType']"}),
+            'help_text': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'limit_choices_to': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'max_digits': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'max_length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'model': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.Model']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'null': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'on_delete': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'othermodel': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'othermodel_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'primary_key': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'related_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'through': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'through_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'to_field': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'foreign_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'unique_for_date': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'date_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_month': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'month_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_year': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'year_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'upload_to': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'verbose_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'})
+        },
+        'django_helper.fieldtype': {
+            'Meta': {'object_name': 'FieldType'},
+            'backend_storage': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'django_helper.middleware': {
+            'Meta': {'object_name': 'Middleware'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'process_exception': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_request': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_template_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        'django_helper.model': {
+            'Meta': {'object_name': 'Model'},
+            'absolute_url': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'}),
+            'date_hierarchy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'exclude': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'exclude_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'fields': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'field_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'filter_horizontal': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'hfilter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'filter_vertical': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vfilter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'inlines': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.Model']", 'null': 'True', 'blank': 'True'}),
+            'list_display': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'display_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'list_filter': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'filter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'raw_id_fields': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'rawid_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'unicode': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'unicode_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unicode_str': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'})
+        },
+        'django_helper.templatetag': {
+            'Meta': {'object_name': 'TemplateTag'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'examples': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'parameters': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
+            'required_context': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.ContextProcessor']", 'symmetrical': 'False', 'blank': 'True'}),
+            'tag_name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tag_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'takes_context': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'template': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['django_helper']

django_helper/migrations/0005_auto__chg_field_model_date_hierarchy.py

+# -*- coding: 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):
+
+        # Renaming column for 'Model.date_hierarchy' to match new field type.
+        db.rename_column('django_helper_model', 'date_hierarchy', 'date_hierarchy_id')
+        # Changing field 'Model.date_hierarchy'
+        db.alter_column('django_helper_model', 'date_hierarchy_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['django_helper.Field']))
+        # Adding index on 'Model', fields ['date_hierarchy']
+        db.create_index('django_helper_model', ['date_hierarchy_id'])
+
+
+    def backwards(self, orm):
+        # Removing index on 'Model', fields ['date_hierarchy']
+        db.delete_index('django_helper_model', ['date_hierarchy_id'])
+
+
+        # Renaming column for 'Model.date_hierarchy' to match new field type.
+        db.rename_column('django_helper_model', 'date_hierarchy_id', 'date_hierarchy')
+        # Changing field 'Model.date_hierarchy'
+        db.alter_column('django_helper_model', 'date_hierarchy', self.gf('django.db.models.fields.BooleanField')())
+
+    models = {
+        'django_helper.contextprocessor': {
+            'Meta': {'object_name': 'ContextProcessor'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'required_middleware': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.Middleware']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'django_helper.field': {
+            'Meta': {'object_name': 'Field'},
+            'auto_now': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'auto_now_add': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'blank': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_column': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_index': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'db_table': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'db_tablespace': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'decimal_places': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'default': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'editable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'field_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.FieldType']"}),
+            'help_text': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'limit_choices_to': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'max_digits': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'max_length': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'model': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.Model']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'null': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'on_delete': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'othermodel': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'othermodel_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'primary_key': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'related_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}),
+            'through': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'through_set'", 'null': 'True', 'to': "orm['django_helper.Model']"}),
+            'to_field': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'foreign_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'unique_for_date': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'date_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_month': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'month_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unique_for_year': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'year_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'upload_to': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'verbose_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'})
+        },
+        'django_helper.fieldtype': {
+            'Meta': {'object_name': 'FieldType'},
+            'backend_storage': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+        },
+        'django_helper.middleware': {
+            'Meta': {'object_name': 'Middleware'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'process_exception': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_request': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_template_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'process_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+        },
+        'django_helper.model': {
+            'Meta': {'object_name': 'Model'},
+            'absolute_url': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'}),
+            'date_hierarchy': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'hierarchy_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'exclude': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'exclude_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'fields': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'field_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'filter_horizontal': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'hfilter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'filter_vertical': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'vfilter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'inlines': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['django_helper.Model']", 'null': 'True', 'blank': 'True'}),
+            'list_display': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'display_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'list_filter': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'filter_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+            'raw_id_fields': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'rawid_set'", 'blank': 'True', 'to': "orm['django_helper.Field']"}),
+            'unicode': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'unicode_set'", 'null': 'True', 'to': "orm['django_helper.Field']"}),
+            'unicode_str': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'})
+        },
+        'django_helper.templatetag': {
+            'Meta': {'object_name': 'TemplateTag'},
+            'added_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'app_name': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'examples': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'parameters': ('django.db.models.fields.CharField', [], {'max_length': '60', 'blank': 'True'}),
+            'required_context': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['django_helper.ContextProcessor']", 'symmetrical': 'False', 'blank': 'True'}),
+            'tag_name': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
+            'tag_type': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
+            'takes_context': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'template': ('django.db.models.fields.CharField', [], {'max_length': '80', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['django_helper']

django_helper/models.py

 
 class Model(models.Model):
     name = models.CharField(max_length=40)
+    unicode = models.ForeignKey('Field', blank=True, null=True, related_name='unicode_set')
+    unicode_str = models.CharField(max_length=80, blank=True)
+    absolute_url = models.CharField(max_length=80, blank=True)
+    date_hierarchy = models.ForeignKey('Field', blank=True, null=True, related_name='hierarchy_set')
+    exclude = models.ManyToManyField('Field', blank=True, related_name='exclude_set')
+    fields = models.ManyToManyField('Field', blank=True, related_name='field_set')
+    filter_horizontal = models.ManyToManyField('Field', blank=True, related_name='hfilter_set')
+    filter_vertical = models.ManyToManyField('Field', blank=True, related_name='vfilter_set')
+    inlines = models.ForeignKey('self', blank=True, null=True)
+    list_display = models.ManyToManyField('Field', blank=True, related_name='display_set')
+    list_filter = models.ManyToManyField('Field', blank=True, related_name='filter_set')
+    raw_id_fields = models.ManyToManyField('Field', blank=True, related_name='rawid_set')
     def __unicode__(self):
         return u"%s" % self.name
 
     max_length = models.IntegerField(blank=True, null=True)
     auto_now = models.BooleanField()
     auto_now_add = models.BooleanField()
-    max_digits = models.IntegerField()
-    decimal_places = models.IntegerField()
+    max_digits = models.IntegerField(blank=True, null=True)
+    decimal_places = models.IntegerField(blank=True, null=True)
     upload_to = models.CharField(max_length=80, blank=True, null=True)
     othermodel = models.ForeignKey(Model, blank=True, null=True, related_name='othermodel_set')
     limit_choices_to = models.CharField(max_length=40, blank=True, null=True)
     db_table = models.CharField(max_length=40, blank=True, null=True)
     def __unicode__(self):
         return u"%s" % self.name
+    def get_field_options(self):
+        ft = self.field_type.backend_storage
+        options = []
+        if ft == 1:
+            max_length = self.max_length if self.max_length else 75
+            options.append("max_length=%d" % max_length)
+        exclude = ['id', 'name', 'model', 'field_type']
+        for f in self._meta.fields:
+            if f.name in exclude:
+                continue
+            if getattr(self, f.attname):
+                options.append("%s=%s" % (f.name, getattr(self, f.attname)))
+        return ', '.join(options)

django_helper/templates/admin/django_helper/admin.txt

+from django.contrib import admin
+from models import {{model}}
+
+{% if model.inlines %}class {{model.inlines}}Inline(admin.TabularInline):
+    model = {{model.inlines}}{% endif %}
+class {{model}}Admin(admin.ModelAdmin):
+{% if model.date_hierarchy %}
+    date_hierarchy = '{{model.date_hierarchy}}'{% endif %}{% if model.exclude.count > 0 %}
+    exclude = ({% for field in model.exclude.all %}'{{field}}', {% endfor %}){% endif %}{% if model.fields.count > 0 %}
+    fields = ({% for field in model.fields.all %}'{{field}}', {% endfor %}){% endif %}{% if model.filter_horizontal.count > 0 %}
+    filter_horizontal = ({% for field in model.filter_horizontal.all %}'{{field}}', {% endfor %}){% endif %}{% if model.filter_vertical.count > 0 %}
+    filter_vertical = ({% for field in model.filter_vertical.all %}'{{field}}', {% endfor %}){% endif %}{% if model.inlines %}
+    inlines = [{{model.inlines}}Inline,]{% endif %}{% if model.list_display.count > 0 %}
+    list_display = ({% for field in model.list_display.all %}'{{field}}', {% endfor %}){% endif %}{% if model.list_filter.count > 0 %}
+    list_filter = ({% for field in model.list_filter.all %}'{{field}}', {% endfor %}){% endif %}{% if model.raw_id_fields.count > 0 %}
+    raw_id_fields = ({% for field in model.raw_id_fields.all %}'{{field}}', {% endfor %}){% endif %}
+
+admin.site.register({{model}}, {{model}}Admin)

django_helper/templates/admin/django_helper/admins.txt

+from django.contrib import admin
+from models import {% for model in model_list %}{{model}}{% if not forloop.last %}, {% endif %}{% endfor %}
+{% for model in model_list %}
+{% if model.inlines %}class {{model.inlines}}Inline(admin.TabularInline):
+    model = {{model.inlines}}{% endif %}
+{% endfor %}{% for model in model_list %}
+class {{model}}Admin(admin.ModelAdmin):{% if model.date_hierarchy %}
+    date_hierarchy = '{{model.date_hierarchy}}'{% endif %}{% if model.exclude.count > 0 %}
+    exclude = ({% for field in model.exclude.all %}'{{field}}', {% endfor %}){% endif %}{% if model.fields.count > 0 %}
+    fields = ({% for field in model.fields.all %}'{{field}}', {% endfor %}){% endif %}{% if model.filter_horizontal.count > 0 %}
+    filter_horizontal = ({% for field in model.filter_horizontal.all %}'{{field}}', {% endfor %}){% endif %}{% if model.filter_vertical.count > 0 %}
+    filter_vertical = ({% for field in model.filter_vertical.all %}'{{field}}', {% endfor %}){% endif %}{% if model.inlines %}
+    inlines = [{{model.inlines}}Inline,]{% endif %}{% if model.list_display.count > 0 %}
+    list_display = ({% for field in model.list_display.all %}'{{field}}', {% endfor %}){% endif %}{% if model.list_filter.count > 0 %}
+    list_filter = ({% for field in model.list_filter.all %}'{{field}}', {% endfor %}){% endif %}{% if model.raw_id_fields.count > 0 %}
+    raw_id_fields = ({% for field in model.raw_id_fields.all %}'{{field}}', {% endfor %}){% endif %}{% endfor %}
+{% for model in model_list %}
+admin.site.register({{model}}, {{model}}Admin)
+{% endfor %}

django_helper/templates/admin/django_helper/model.txt

+from django.db import models
+
+class {{model}}(models.Model):{% for field in model.field_set.all %}
+    {{field}} = models.{{field.field_type}}({{field.get_field_options}}){% endfor %}
+    def __unicode__(self):
+        return {% if model.unicode %}u"%s" % self.{{model.unicode}}{% else %}{{model.unicode_str}}{% endif %}
+    @models.permalink
+    def get_absolute_url(self):
+        return {{model.absolute_url}}

django_helper/templates/admin/django_helper/model/change_form.html

+{% extends "admin/change_form.html" %}
+{% load i18n %}
+
+{% block object-tools %}
+{% if change %}{% if not popup %}
+  <ul class="object-tools">
+    <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
+    <li><a href="export/models.py" class="historylink">Export models.py</a></li>
+    <li><a href="export/admin.py" class="historylink">Export admin.py</a></li>
+    {% if has_absolute_url %}
+      <li><a href="../../../r/{{content_type_id}}/{{object_id}}/" class="viewsitelink">
+          {% trans "View on site" %}</a>
+      </li>
+    {% endif %}
+  </ul>
+{% endif %}{% endif %}
+{% endblock %}

django_helper/templates/admin/django_helper/models.txt

+from django.db import models
+{% for model in model_list %}
+class {{model}}(models.Model):{% for field in model.field_set.all %}
+    {{field}} = models.{{field.field_type}}({{field.get_field_options}}){% endfor %}
+    def __unicode__(self):
+        return {% if model.unicode %}u"%s" % self.{{model.unicode}}{% else %}{{model.unicode_str}}{% endif %}
+    @models.permalink
+    def get_absolute_url(self):
+        return {{model.absolute_url}}
+{% endfor %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.