diff --git a/apps/dashboard/migrations/0001_initial.py b/apps/dashboard/migrations/0001_initial.py new file mode 100644 index 0000000..87994eb --- /dev/null +++ b/apps/dashboard/migrations/0001_initial.py @@ -0,0 +1,20 @@ +# Generated by Django 6.0 on 2025-12-31 05:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Item', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + ] diff --git a/apps/dashboard/migrations/0002_item_text.py b/apps/dashboard/migrations/0002_item_text.py new file mode 100644 index 0000000..0c2fab1 --- /dev/null +++ b/apps/dashboard/migrations/0002_item_text.py @@ -0,0 +1,18 @@ +# Generated by Django 6.0 on 2025-12-31 05:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dashboard', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='item', + name='text', + field=models.TextField(default=''), + ), + ] diff --git a/apps/dashboard/models.py b/apps/dashboard/models.py index 71a8362..201edc2 100644 --- a/apps/dashboard/models.py +++ b/apps/dashboard/models.py @@ -1,3 +1,4 @@ from django.db import models -# Create your models here. +class Item(models.Model): + text = models.TextField(default='') diff --git a/apps/dashboard/tests.py b/apps/dashboard/tests.py index e2eece8..13593bb 100644 --- a/apps/dashboard/tests.py +++ b/apps/dashboard/tests.py @@ -1,4 +1,5 @@ from django.test import TestCase +from .models import Item class HomePageTest(TestCase): def test_uses_home_template(self): @@ -13,4 +14,22 @@ class HomePageTest(TestCase): def test_can_save_a_POST_request(self): response = self.client.post('/', data={'item-text': 'A new dashboard item'}) self.assertContains(response, 'A new dashboard item') - self.assertTemplateUsed(response, 'apps/dashboard/home.html') \ No newline at end of file + self.assertTemplateUsed(response, 'apps/dashboard/home.html') + +class ItemModelTest(TestCase): + def test_saving_and_retrieving_items(self): + first_item = Item() + first_item.text = "The first (ever) dashboard item" + first_item.save() + + second_item = Item() + second_item.text = "A sequel somehow better than the first" + second_item.save() + + saved_items = Item.objects.all() + self.assertEqual(saved_items.count(), 2) + + first_saved_item = saved_items[0] + second_saved_item = saved_items[1] + self.assertEqual(first_saved_item.text, "The first (ever) dashboard item") + self.assertEqual(second_saved_item.text, "A sequel somehow better than the first") \ No newline at end of file diff --git a/functional_tests.py b/functional_tests.py index 1140b42..753d95d 100644 --- a/functional_tests.py +++ b/functional_tests.py @@ -41,7 +41,5 @@ class NewVisitorTest(unittest.TestCase): self.check_for_row_in_list_table('2: Use peacock feathers to make a fly') self.check_for_row_in_list_table('1: Buy peacock feathers') - - if __name__ == "__main__": unittest.main() \ No newline at end of file