From 88fe7b7e797cf029ad50cede0bf22857d89b8729 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Wed, 7 Aug 2013 22:47:31 +1000 Subject: [PATCH] Added description and question and answer models --- project_directory/db.sqlite3 | Bin 147456 -> 159744 bytes project_directory/three_d_viewer/admin.py | 4 +- ...0002_auto__add_field_sample_description.py | 41 +++++++++++ .../0003_auto__add_question__add_answer.py | 69 ++++++++++++++++++ project_directory/three_d_viewer/models.py | 20 +++++ .../templates/three_d_viewer/detail.html | 2 +- 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 project_directory/three_d_viewer/migrations/0002_auto__add_field_sample_description.py create mode 100644 project_directory/three_d_viewer/migrations/0003_auto__add_question__add_answer.py diff --git a/project_directory/db.sqlite3 b/project_directory/db.sqlite3 index 2cbb5dded996db296dcbed8728552f4a0bce2097..3642fec93f18bc4764a8de5c2fbdeb0b38cad53e 100644 GIT binary patch delta 2879 zcma)8Yiv{J89uLld^y+G4WJZ)@rmO!aTA+!e2FhC5R;{si4ZP9{Fpj(h|jPkV+Y5y zo3vsQs)-*(YZB;be{|EBG^r9l))_6UDwPS*X}zdx*(O$Lt#*~h)HY)h+7FP}ch0ec zW6ZY5d34_Id%pL5zVCg%%jwh1=|3_r^*oZNC~AQGH~+q}I2?ui8%KVC?k<5e2H4`V z%QMPz!<>!%J^OQZi7nRmd$zK*K)^w5hkFK-j$Ol16#ql#mw=2pJ(HY_9K@-sNi>Xc&OD z8Cz}Z=GW(;p%?i36Y_7OVF=o__gbxOI;Ace`eB_cpBaPA)n5q}FZS@_SqlGzAK;t# zJ*?n2FoPS#Rq;ddb#X;`2@XU3h}0!K;o}|D=HO;4FV%cS)3UkjvjvUh%xdf79F#Zc zZO(l?rP*5l@Us!v%8R!t{0@GGU*Jbr$M2KCs(2eG5OJvfi2OTod1!S*U!x#;=%5!m zd*kXutDneQIN=mU9G%56@s4;&d|uou`h5Ps-@gqwOrC{<7Tbpq*=A1m8xNxwZ```!UN-FB}_&~l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-ax0_4+A gTz`%m?RJJSdT9J&Es><>Q`}(Wg*L!$fXyKO2f$N1JOBUy delta 571 zcmXw$Ur1A77{Qc!TLt@!uwu4&+p>ld1GZc7L)Hb z*98b6yV?GqmSo2P2s}OW0Nt90iC#67l8kP<-_%q))cj1~y`E%BGP~_M|1po9+&4Ve zr07M0YxoYAa00L3X$)e6UeSvT$?A4-^&m7U*iP^UuHpuk(8gH?M(`-MGXycU^?jRt zxboVs@MsYRB+z0;7gB3Kyb=Km1Pe@fj*@qZ^>zSMVVL1>V(sA2|jU7?kX$`_JZCAPWm!Lp(ey# zSxYcFw?l%sL9UliDyDKu)wG;vNw@SB9F<1J52DXC?=pon|ANbNK1kU8#sCQM9X^R} z%s?BxHUl~>-viNkn}nA@JxORY%;VwS-o5d#S85CdU_3~Dv(P|G8F14~2D0?qG~A}= zr(v9aoq{oXXbPUtJCm?Ll}Whi1h2EK&YSyS@u1k?ueQ!v#$pKsgO#>P@DKjPO;*Sk z+$Hcb@U_G7yeup1i9A*a{>Ck=FkTFilHIHJk@!oR&;s=NRI diff --git a/project_directory/three_d_viewer/admin.py b/project_directory/three_d_viewer/admin.py index b8930a3..d98e024 100644 --- a/project_directory/three_d_viewer/admin.py +++ b/project_directory/three_d_viewer/admin.py @@ -1,5 +1,7 @@ from django.contrib import admin -from three_d_viewer.models import Category, Sample +from three_d_viewer.models import Category, Sample, Question, Answer admin.site.register(Category) admin.site.register(Sample) +admin.site.register(Question) +admin.site.register(Answer) diff --git a/project_directory/three_d_viewer/migrations/0002_auto__add_field_sample_description.py b/project_directory/three_d_viewer/migrations/0002_auto__add_field_sample_description.py new file mode 100644 index 0000000..6e130a9 --- /dev/null +++ b/project_directory/three_d_viewer/migrations/0002_auto__add_field_sample_description.py @@ -0,0 +1,41 @@ +# -*- 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 'Sample.description' + db.add_column(u'three_d_viewer_sample', 'description', + self.gf('django.db.models.fields.CharField')(default='', max_length=2000, null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Sample.description' + db.delete_column(u'three_d_viewer_sample', 'description') + + + models = { + u'three_d_viewer.category': { + 'Meta': {'object_name': 'Category'}, + 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': u"orm['three_d_viewer.Category']"}) + }, + u'three_d_viewer.sample': { + 'Meta': {'object_name': 'Sample'}, + 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'description': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2000', 'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model_filename': ('django.db.models.fields.CharField', [], {'max_length': '1000'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['three_d_viewer.Category']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'}) + } + } + + complete_apps = ['three_d_viewer'] \ No newline at end of file diff --git a/project_directory/three_d_viewer/migrations/0003_auto__add_question__add_answer.py b/project_directory/three_d_viewer/migrations/0003_auto__add_question__add_answer.py new file mode 100644 index 0000000..9b0e694 --- /dev/null +++ b/project_directory/three_d_viewer/migrations/0003_auto__add_question__add_answer.py @@ -0,0 +1,69 @@ +# -*- 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 model 'Question' + db.create_table(u'three_d_viewer_question', ( + (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('text', self.gf('django.db.models.fields.CharField')(max_length=2000)), + ('sample', self.gf('django.db.models.fields.related.ForeignKey')(related_name='questions', to=orm['three_d_viewer.Sample'])), + )) + db.send_create_signal(u'three_d_viewer', ['Question']) + + # Adding model 'Answer' + db.create_table(u'three_d_viewer_answer', ( + (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('text', self.gf('django.db.models.fields.CharField')(max_length=2000)), + ('correct', self.gf('django.db.models.fields.BooleanField')(default=False)), + ('question', self.gf('django.db.models.fields.related.ForeignKey')(related_name='answers', to=orm['three_d_viewer.Question'])), + )) + db.send_create_signal(u'three_d_viewer', ['Answer']) + + + def backwards(self, orm): + # Deleting model 'Question' + db.delete_table(u'three_d_viewer_question') + + # Deleting model 'Answer' + db.delete_table(u'three_d_viewer_answer') + + + models = { + u'three_d_viewer.answer': { + 'Meta': {'object_name': 'Answer'}, + 'correct': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'answers'", 'to': u"orm['three_d_viewer.Question']"}), + 'text': ('django.db.models.fields.CharField', [], {'max_length': '2000'}) + }, + u'three_d_viewer.category': { + 'Meta': {'object_name': 'Category'}, + 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': u"orm['three_d_viewer.Category']"}) + }, + u'three_d_viewer.question': { + 'Meta': {'object_name': 'Question'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'sample': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questions'", 'to': u"orm['three_d_viewer.Sample']"}), + 'text': ('django.db.models.fields.CharField', [], {'max_length': '2000'}) + }, + u'three_d_viewer.sample': { + 'Meta': {'object_name': 'Sample'}, + 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'description': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2000', 'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model_filename': ('django.db.models.fields.CharField', [], {'max_length': '1000'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['three_d_viewer.Category']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'}) + } + } + + complete_apps = ['three_d_viewer'] \ No newline at end of file diff --git a/project_directory/three_d_viewer/models.py b/project_directory/three_d_viewer/models.py index 018c8f7..6fa6fb6 100644 --- a/project_directory/three_d_viewer/models.py +++ b/project_directory/three_d_viewer/models.py @@ -20,5 +20,25 @@ class Category(CommonInfo): class Sample(CommonInfo): model_filename = models.CharField(max_length=1000) + description = models.CharField(max_length=2000, default='', blank=True, null=True) parent = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL) + + +class Question(models.Model): + text = models.CharField(max_length=2000) + sample = models.ForeignKey(Sample, related_name='questions') + + def correct_answers(self): + return self.answers.filter(correct = True) + + def __unicode__(self): + return self.text + +class Answer(models.Model): + text = models.CharField(max_length=2000) + correct = models.BooleanField(default=False) + question = models.ForeignKey(Question, related_name='answers') + + def __unicode__(self): + return self.text diff --git a/project_directory/three_d_viewer/templates/three_d_viewer/detail.html b/project_directory/three_d_viewer/templates/three_d_viewer/detail.html index 158c9fd..83d15a6 100644 --- a/project_directory/three_d_viewer/templates/three_d_viewer/detail.html +++ b/project_directory/three_d_viewer/templates/three_d_viewer/detail.html @@ -3,7 +3,7 @@

{{ sample.name }}

- +{{ sample.description }} js-openctm - Demo