diff --git a/studyguides/apps/courses/migrations/0001_initial.py b/studyguides/apps/courses/migrations/0001_initial.py index c7ec934..14a431f 100644 --- a/studyguides/apps/courses/migrations/0001_initial.py +++ b/studyguides/apps/courses/migrations/0001_initial.py @@ -1,7 +1,8 @@ -# Generated by Django 3.1.2 on 2020-10-14 18:22 +# Generated by Django 3.1.2 on 2020-10-15 19:30 import django.core.validators from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -17,14 +18,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(primary_key=True, serialize=False)), ('name', models.CharField(max_length=100, unique=True)), - ], - ), - migrations.CreateModel( - name='Guide', - fields=[ - ('id', models.AutoField(primary_key=True, serialize=False)), - ('name', models.CharField(max_length=100)), - ('url', models.URLField(max_length=300)), + ('url', models.CharField(max_length=20, unique=True, validators=[django.core.validators.RegexValidator(message='Only alphanumeric, dashes, and underscores allowed', regex='^[a-zA-Z0-9_\\-]+$')])), ], ), migrations.CreateModel( @@ -36,9 +30,14 @@ class Migration(migrations.Migration): ('courses', models.ManyToManyField(related_name='subject', to='courses.Course')), ], ), - migrations.AddField( - model_name='course', - name='units', - field=models.ManyToManyField(related_name='course', to='courses.Guide'), + migrations.CreateModel( + name='Guide', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=100)), + ('teacher', models.CharField(blank=True, max_length=100)), + ('url', models.URLField(max_length=300)), + ('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.course')), + ], ), ] diff --git a/studyguides/apps/courses/migrations/0002_auto_20201015_1932.py b/studyguides/apps/courses/migrations/0002_auto_20201015_1932.py new file mode 100644 index 0000000..f3447de --- /dev/null +++ b/studyguides/apps/courses/migrations/0002_auto_20201015_1932.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.2 on 2020-10-15 19:32 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='course', + name='url', + ), + migrations.AlterField( + model_name='subject', + name='url', + field=models.CharField(max_length=20, unique=True, validators=[django.core.validators.RegexValidator(message='Only alphanumeric, dashes, and underscores allowed', regex='^[a-zA-Z0-9_\\-]+$')], verbose_name='URL'), + ), + ] diff --git a/studyguides/apps/courses/migrations/0003_course_url.py b/studyguides/apps/courses/migrations/0003_course_url.py new file mode 100644 index 0000000..d30be34 --- /dev/null +++ b/studyguides/apps/courses/migrations/0003_course_url.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.2 on 2020-10-15 19:33 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0002_auto_20201015_1932'), + ] + + operations = [ + migrations.AddField( + model_name='course', + name='url', + field=models.CharField(default='test', max_length=20, unique=True, validators=[django.core.validators.RegexValidator(message='Only alphanumeric, dashes, and underscores allowed', regex='^[a-zA-Z0-9_\\-]+$')], verbose_name='URL'), + preserve_default=False, + ), + ] diff --git a/studyguides/apps/courses/models.py b/studyguides/apps/courses/models.py index d94f3e0..2917eec 100644 --- a/studyguides/apps/courses/models.py +++ b/studyguides/apps/courses/models.py @@ -7,7 +7,7 @@ from django.core.validators import RegexValidator, FileExtensionValidator class Subject(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=100, unique=True) - url = models.CharField(max_length=20, unique=True, validators=[RegexValidator( + url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator( regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")]) courses = models.ManyToManyField("Course", related_name="subject") @@ -19,6 +19,8 @@ class Subject(models.Model): class Course(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=100, unique=True) + url = models.CharField("URL", max_length=20, unique=True, validators=[RegexValidator( + regex="^[a-zA-Z0-9_\-]+$", message="Only alphanumeric, dashes, and underscores allowed")]) def __str__(self): return self.name diff --git a/studyguides/templates/home.html b/studyguides/templates/home.html index 9c8f27f..e580f4e 100644 --- a/studyguides/templates/home.html +++ b/studyguides/templates/home.html @@ -4,7 +4,7 @@

{{ subject.name }}

{% for course in courses %} -

{{ course.name }}

+

{{ course.name }}

{% endfor %} {% endfor %}