Skip to content

Commit

Permalink
Updated the dummy-data command to properly render model names in admi…
Browse files Browse the repository at this point in the history
…n panel.
  • Loading branch information
taoteg committed Nov 29, 2017
1 parent a4290cb commit 5593f3f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
5 changes: 1 addition & 4 deletions project/apps/core/management/commands/dummy-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ def add_arguments(self, parser):

# def handle(self, *args, **options):
# raise NotImplementedError()
#
# # Test that the command is working:
# print('Generating dummy data...')


def handle(self, *args, **options):
Expand Down Expand Up @@ -54,7 +51,7 @@ def make_universities(self):


def make_courses(self):
template_options = ['CS%s0%s', 'MATH%s0%s', 'CHEM%s0%s', 'PHYS%s0%s'] # , 'BIO%s0%s'
template_options = ['CS%s0%s', 'MATH%s0%s', 'CHEM%s0%s', 'PHYS%s0%s']
self.courses = []
for num in range(1, 4):
for course_num in range(1, 4):
Expand Down
27 changes: 8 additions & 19 deletions project/apps/core/management/commands/push-to-index.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
import random # ADDED.
import names # ADDED.

from model_mommy import mommy # ADDED.

from django.core.management.base import BaseCommand
from core.models import University, Course, Student

# ADDED.
from model_mommy import mommy
import random
import names


class Command(BaseCommand):
help = "My shiny new management command."


def add_arguments(self, parser):
# parser.add_argument('sample', nargs='+')

# Take arg for number of students to generate.
parser.add_argument('count', nargs=1, type=int)


# def handle(self, *args, **options):
# raise NotImplementedError()
#
# # Test that the command is working:
# print('Generating dummy data...')


def handle(self, *args, **options):
# TEST COMMAND WORKS.
print('Generating dummy data...')

# print('Generating dummy data...')
# GENERATE THE DUMMY DATA.
self.clear()
self.make_universities()
Expand All @@ -44,17 +35,15 @@ def clear(self):


def make_universities(self):
university_names = (
'UT', 'TAMU', 'MIT', 'MGU', 'CalTech', 'KPI', 'DPI', 'PSTU'
)
university_names = ('UT', 'TAMU', 'MIT', 'MGU', 'CalTech', 'KPI', 'DPI', 'PSTU')
self.universities = []
for name in university_names:
uni = mommy.make(University, name=name)
self.universities.append(uni)


def make_courses(self):
template_options = ['CS%s0%s', 'MATH%s0%s', 'CHEM%s0%s', 'PHYS%s0%s'] # , 'BIO%s0%s'
template_options = ['CS%s0%s', 'MATH%s0%s', 'CHEM%s0%s', 'PHYS%s0%s']
self.courses = []
for num in range(1, 4):
for course_num in range(1, 4):
Expand Down
14 changes: 14 additions & 0 deletions project/apps/core/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
# from django.contrib.contenttypes import generic


class University(models.Model):
name = models.CharField(max_length=255, unique=True)

# def __unicode__(self): # Python 2.
def __str__(self): # Python 3.
return self.name


class Course(models.Model):
name = models.CharField(max_length=255, unique=True)

# def __unicode__(self): # Python 2..
def __str__(self): # Python 3.
return self.name


class Student(models.Model):
YEAR_IN_SCHOOL_CHOICES = (
Expand All @@ -25,6 +34,11 @@ class Student(models.Model):
)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)

# various relationships models
university = models.ForeignKey(University, null=True, blank=True)
courses = models.ManyToManyField(Course, null=True, blank=True)

# def __unicode__(self): # Python 2..
def __str__(self): # Python 3.
return (self.last_name + ', ' + self.first_name)
Binary file modified project/db/development.db
Binary file not shown.

0 comments on commit 5593f3f

Please sign in to comment.