diff --git a/core/migrations/0005_auto__add_finetoothuser__add_field_comment_commenter__add_field_vote_v.py b/core/migrations/0005_auto__add_finetoothuser__add_field_comment_commenter__add_field_vote_v.py new file mode 100644 index 0000000..e39dcfc --- /dev/null +++ b/core/migrations/0005_auto__add_finetoothuser__add_field_comment_commenter__add_field_vote_v.py @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as 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 'FinetoothUser' + db.create_table('core_finetoothuser', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('password', self.gf('django.db.models.fields.CharField')(max_length=128)), + ('last_login', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), + ('is_superuser', self.gf('django.db.models.fields.BooleanField')(default=False)), + ('username', self.gf('django.db.models.fields.CharField')(max_length=30, unique=True)), + ('first_name', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)), + ('last_name', self.gf('django.db.models.fields.CharField')(max_length=30, blank=True)), + ('email', self.gf('django.db.models.fields.EmailField')(max_length=75, blank=True)), + ('is_staff', self.gf('django.db.models.fields.BooleanField')(default=False)), + ('is_active', self.gf('django.db.models.fields.BooleanField')(default=True)), + ('date_joined', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), + ('location', self.gf('django.db.models.fields.CharField')(max_length=100)), + ('url', self.gf('django.db.models.fields.URLField')(max_length=200)), + )) + db.send_create_signal('core', ['FinetoothUser']) + + # Adding M2M table for field groups on 'FinetoothUser' + m2m_table_name = db.shorten_name('core_finetoothuser_groups') + db.create_table(m2m_table_name, ( + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), + ('finetoothuser', models.ForeignKey(orm['core.finetoothuser'], null=False)), + ('group', models.ForeignKey(orm['auth.group'], null=False)) + )) + db.create_unique(m2m_table_name, ['finetoothuser_id', 'group_id']) + + # Adding M2M table for field user_permissions on 'FinetoothUser' + m2m_table_name = db.shorten_name('core_finetoothuser_user_permissions') + db.create_table(m2m_table_name, ( + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), + ('finetoothuser', models.ForeignKey(orm['core.finetoothuser'], null=False)), + ('permission', models.ForeignKey(orm['auth.permission'], null=False)) + )) + db.create_unique(m2m_table_name, ['finetoothuser_id', 'permission_id']) + + # Adding field 'Comment.commenter' + db.add_column('core_comment', 'commenter', + self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['core.FinetoothUser']), + keep_default=False) + + # Adding field 'Vote.voter' + db.add_column('core_vote', 'voter', + self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['core.FinetoothUser']), + keep_default=False) + + # Adding field 'Post.author' + db.add_column('core_post', 'author', + self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['core.FinetoothUser']), + keep_default=False) + + + def backwards(self, orm): + # Deleting model 'FinetoothUser' + db.delete_table('core_finetoothuser') + + # Removing M2M table for field groups on 'FinetoothUser' + db.delete_table(db.shorten_name('core_finetoothuser_groups')) + + # Removing M2M table for field user_permissions on 'FinetoothUser' + db.delete_table(db.shorten_name('core_finetoothuser_user_permissions')) + + # Deleting field 'Comment.commenter' + db.delete_column('core_comment', 'commenter_id') + + # Deleting field 'Vote.voter' + db.delete_column('core_vote', 'voter_id') + + # Deleting field 'Post.author' + db.delete_column('core_post', 'author_id') + + + models = { + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '80', 'unique': 'True'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'blank': 'True', 'to': "orm['auth.Permission']"}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + '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': '50'}) + }, + 'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'db_table': "'django_content_type'", 'object_name': 'ContentType'}, + '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'}) + }, + 'core.comment': { + 'Meta': {'object_name': 'Comment'}, + 'commenter': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.FinetoothUser']"}), + 'content': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'post': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Post']"}) + }, + 'core.commentvote': { + 'Meta': {'_ormbases': ['core.Vote'], 'object_name': 'CommentVote'}, + 'comment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Comment']"}), + 'vote_ptr': ('django.db.models.fields.related.OneToOneField', [], {'primary_key': 'True', 'unique': 'True', 'to': "orm['core.Vote']"}) + }, + 'core.finetoothuser': { + 'Meta': {'object_name': 'FinetoothUser'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'blank': 'True', 'to': "orm['auth.Group']", 'related_name': "'user_set'"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'blank': 'True', 'to': "orm['auth.Permission']", 'related_name': "'user_set'"}), + 'username': ('django.db.models.fields.CharField', [], {'max_length': '30', 'unique': 'True'}) + }, + 'core.post': { + 'Meta': {'object_name': 'Post'}, + 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.FinetoothUser']"}), + 'content': ('django.db.models.fields.TextField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}) + }, + 'core.postvote': { + 'Meta': {'_ormbases': ['core.Vote'], 'object_name': 'PostVote'}, + 'post': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.Post']"}), + 'vote_ptr': ('django.db.models.fields.related.OneToOneField', [], {'primary_key': 'True', 'unique': 'True', 'to': "orm['core.Vote']"}) + }, + 'core.vote': { + 'Meta': {'object_name': 'Vote'}, + 'end_index': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'start_index': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'value': ('django.db.models.fields.IntegerField', [], {}), + 'voter': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['core.FinetoothUser']"}) + } + } + + complete_apps = ['core'] \ No newline at end of file diff --git a/core/models.py b/core/models.py index d0192db..f4fa71b 100644 --- a/core/models.py +++ b/core/models.py @@ -1,10 +1,13 @@ from django.db import models +from django.contrib.auth.models import AbstractUser from core.votable import VotableMixin -# TODO: users; probably want to subclass Django's AbstractUser +class FinetoothUser(AbstractUser): + location = models.CharField(max_length=100) + url = models.URLField() class Post(models.Model, VotableMixin): - # TODO: "author" attribute will be ForeignKey to user model + author = models.ForeignKey("FinetoothUser") title = models.CharField(max_length=200) content = models.TextField() # TODO: date published (a DateTimeField), definitely! Maybe date @@ -21,7 +24,7 @@ def vote_set(self): class Comment(models.Model, VotableMixin): - # TODO: "author" attribute will be, &c. + commenter = models.ForeignKey("FinetoothUser") content = models.TextField() post = models.ForeignKey("Post") @@ -35,7 +38,7 @@ def vote_set(self): class Vote(models.Model): - # TODO: "voter" attribute will be ForeignKey to User + voter = models.ForeignKey("FinetoothUser") value = models.IntegerField() start_index = models.PositiveIntegerField() end_index = models.PositiveIntegerField() @@ -51,3 +54,5 @@ class CommentVote(Vote): def __str__(self): return "{} on comment #{}".format(self.value, self.comment.pk) + + diff --git a/settings.py b/settings.py index 051ae45..3c3f2db 100644 --- a/settings.py +++ b/settings.py @@ -55,6 +55,8 @@ } } +AUTH_USER_MODEL = "core.FinetoothUser" + LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' @@ -69,3 +71,5 @@ STATICFILES_DIRS = ("static",) STATIC_URL = '/static/' + +