Skip to content

Commit

Permalink
6 - Foreign Key Basics
Browse files Browse the repository at this point in the history
  • Loading branch information
jmitchel3 committed Jul 13, 2015
1 parent a3b363e commit c7200b6
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
Binary file modified src/db.sqlite3
Binary file not shown.
6 changes: 4 additions & 2 deletions src/questions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Register your models here.

from .models import Question
from .models import Question, Answer

admin.site.register(Question)
admin.site.register(Question)

admin.site.register(Answer)
Binary file modified src/questions/admin.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions src/questions/migrations/0002_answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('questions', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Answer',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('text', models.CharField(max_length=120)),
('active', models.BooleanField(default=True)),
('draft', models.BooleanField(default=False)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('question', models.ForeignKey(to='questions.Question')),
],
),
]
Binary file added src/questions/migrations/0002_answer.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions src/questions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ class Question(models.Model):
active = models.BooleanField(default=True)
draft = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
#answers = models.ManyToManyField('Answer')

def __unicode__(self): #def __str__(self):
return self.text[:10]


class Answer(models.Model):
question = models.ForeignKey(Question)
text = models.CharField(max_length=120)
active = models.BooleanField(default=True)
draft = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)


def __unicode__(self): #def __str__(self):
return self.text[:10]
Binary file modified src/questions/models.pyc
Binary file not shown.

0 comments on commit c7200b6

Please sign in to comment.