From 77254aa99e7a78055098974ab3e0d2ad9f1cf81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Mon, 26 Feb 2024 21:59:19 +0300 Subject: [PATCH 1/8] ver 1.0 --- src/lizaalert/courses/admin.py | 30 ++++++++++++++ .../migrations/0027_auto_20240225_1638.py | 41 +++++++++++++++++++ src/lizaalert/courses/models.py | 20 +++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/lizaalert/courses/migrations/0027_auto_20240225_1638.py diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index e203d6a5..da6c7a35 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -11,6 +11,7 @@ CourseFaq, CourseKnowledge, CourseProgressStatus, + Direction, Knowledge, Lesson, LessonProgressStatus, @@ -65,6 +66,14 @@ def get_chapter_link(self, obj): get_chapter_link.short_description = "Глава" +class DirectionInline(admin.StackedInline): + """Инлайн направления для отображения в главе.""" + + model = Direction + min_num = 1 + extra = 0 + + @admin.register(Cohort) class CohortAdmin(admin.ModelAdmin): """ @@ -97,6 +106,7 @@ class CourseAdmin(admin.ModelAdmin): """Админка курса.""" inlines = (CourseFaqInline, CourseKnowledgeInline, ChapterInline) + list_filter = ["direction",] model = Course list_display = ( "title", @@ -105,6 +115,7 @@ class CourseAdmin(admin.ModelAdmin): "user_created", "created_at", "updated_at", + "direction", ) ordering = ("-updated_at",) empty_value_display = "-пусто-" @@ -278,3 +289,22 @@ class SubscriptionAdmin(admin.ModelAdmin): ] ordering = ("-updated_at",) + + +@admin.register(Direction) +class DirectionAdmin(admin.ModelAdmin): + """Aдминка для Direction.""" + +# inlines = (CourseKnowledgeInline,) + ordering = ("-updated_at",) +# list_filter = ["courses__direction",] + list_display = ( + "title", + "author", + "created_at", + "updated_at", + "courses" + ) + @admin.display(description="Курсы") + def courses(self, obj): + return list(obj.course_set.all()) diff --git a/src/lizaalert/courses/migrations/0027_auto_20240225_1638.py b/src/lizaalert/courses/migrations/0027_auto_20240225_1638.py new file mode 100644 index 00000000..438be86c --- /dev/null +++ b/src/lizaalert/courses/migrations/0027_auto_20240225_1638.py @@ -0,0 +1,41 @@ +# Generated by Django 3.2.20 on 2024-02-25 13:38 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('courses', '0026_alter_lesson_lesson_type'), + ] + + operations = [ + migrations.CreateModel( + name='Direction', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True, db_index=True)), + ('deleted_at', models.DateTimeField(blank=True, null=True)), + ('title', models.CharField(max_length=250, verbose_name='Название направления')), + ('description', models.CharField(max_length=1000, verbose_name='Описание направления')), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Создатель направления')), + ], + options={ + 'verbose_name': 'Направление', + 'verbose_name_plural': 'Направления', + }, + ), + migrations.AddField( + model_name='course', + name='direction', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.direction', verbose_name='Направление курса'), + ), + migrations.AddConstraint( + model_name='direction', + constraint=models.UniqueConstraint(fields=('title',), name='unique_direction'), + ), + ] diff --git a/src/lizaalert/courses/models.py b/src/lizaalert/courses/models.py index ee3bdaf4..d4014312 100644 --- a/src/lizaalert/courses/models.py +++ b/src/lizaalert/courses/models.py @@ -118,6 +118,13 @@ class CourseStatus(models.IntegerChoices): ) user_created = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель курса") status = models.IntegerField(verbose_name="статус курса", choices=CourseStatus.choices, default=CourseStatus.DRAFT) + direction = models.ForeignKey( + "courses.Direction", + on_delete=models.PROTECT, + verbose_name="Направление курса", + null=True, + blank=True + ) class Meta: verbose_name = "Курс" @@ -587,3 +594,16 @@ def finish(self): """Завершить подписку на курс.""" self.status = Subscription.Status.COMPLETED self.save() + +class Direction(TimeStampedModel): + title = models.CharField(max_length=250, verbose_name="Название направления") + description = models.CharField(max_length=1000, verbose_name="Описание направления") + author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель направления") + + class Meta: + constraints = [models.UniqueConstraint(fields=["title"], name="unique_direction")] + verbose_name = "Направление" + verbose_name_plural = "Направления" + + def __str__(self): + return self.title From 8c4f7f51d2cc0718dc716fd959262b6eab8b82d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Mon, 26 Feb 2024 22:50:05 +0300 Subject: [PATCH 2/8] ver 1.01 --- src/lizaalert/courses/admin.py | 23 +++++----------- .../migrations/0028_auto_20240226_2234.py | 27 +++++++++++++++++++ src/lizaalert/courses/models.py | 14 +++++----- 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 src/lizaalert/courses/migrations/0028_auto_20240226_2234.py diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index da6c7a35..ea8ec08e 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -106,7 +106,9 @@ class CourseAdmin(admin.ModelAdmin): """Админка курса.""" inlines = (CourseFaqInline, CourseKnowledgeInline, ChapterInline) - list_filter = ["direction",] + list_filter = [ + "direction", + ] model = Course list_display = ( "title", @@ -239,12 +241,8 @@ class KnowledgeAdmin(admin.ModelAdmin): inlines = (CourseKnowledgeInline,) ordering = ("-updated_at",) - list_display = ( - "title", - "author", - "created_at", - "updated_at", - ) + list_filter = ("direction",) + list_display = ("title", "author", "created_at", "updated_at", "direction") @admin.register(Lesson) @@ -295,16 +293,9 @@ class SubscriptionAdmin(admin.ModelAdmin): class DirectionAdmin(admin.ModelAdmin): """Aдминка для Direction.""" -# inlines = (CourseKnowledgeInline,) ordering = ("-updated_at",) -# list_filter = ["courses__direction",] - list_display = ( - "title", - "author", - "created_at", - "updated_at", - "courses" - ) + list_display = ("title", "author", "created_at", "updated_at", "courses") + @admin.display(description="Курсы") def courses(self, obj): return list(obj.course_set.all()) diff --git a/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py b/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py new file mode 100644 index 00000000..836e52e6 --- /dev/null +++ b/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.20 on 2024-02-26 19:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0027_auto_20240225_1638'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='knowledge', + name='unique_knowledge', + ), + migrations.AddField( + model_name='knowledge', + name='direction', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.direction', verbose_name='Направление умения'), + ), + migrations.AddConstraint( + model_name='knowledge', + constraint=models.UniqueConstraint(fields=('title', 'direction'), name='unique_knowledge'), + ), + ] diff --git a/src/lizaalert/courses/models.py b/src/lizaalert/courses/models.py index d4014312..f90ea698 100644 --- a/src/lizaalert/courses/models.py +++ b/src/lizaalert/courses/models.py @@ -74,9 +74,14 @@ class Knowledge(TimeStampedModel): title = models.CharField(max_length=250, verbose_name="Название умения") description = models.CharField(max_length=1000, verbose_name="Описание умения") author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель умения") + direction = models.ForeignKey( + "courses.Direction", on_delete=models.PROTECT, verbose_name="Направление умения", null=True, blank=True + ) class Meta: - constraints = [models.UniqueConstraint(fields=["title"], name="unique_knowledge")] + constraints = [ + models.UniqueConstraint(fields=("title", "direction"), name="unique_knowledge"), + ] verbose_name = "Умение" verbose_name_plural = "Умения" @@ -119,11 +124,7 @@ class CourseStatus(models.IntegerChoices): user_created = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель курса") status = models.IntegerField(verbose_name="статус курса", choices=CourseStatus.choices, default=CourseStatus.DRAFT) direction = models.ForeignKey( - "courses.Direction", - on_delete=models.PROTECT, - verbose_name="Направление курса", - null=True, - blank=True + "courses.Direction", on_delete=models.PROTECT, verbose_name="Направление курса", null=True, blank=True ) class Meta: @@ -595,6 +596,7 @@ def finish(self): self.status = Subscription.Status.COMPLETED self.save() + class Direction(TimeStampedModel): title = models.CharField(max_length=250, verbose_name="Название направления") description = models.CharField(max_length=1000, verbose_name="Описание направления") From 6e62b45fe87bb73e6c0da3301265564219b6022a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Fri, 1 Mar 2024 23:38:24 +0300 Subject: [PATCH 3/8] ver 2.0 --- src/lizaalert/courses/admin.py | 29 ++++++++++++------- ...225_1638.py => 0027_auto_20240229_2149.py} | 12 ++++---- .../migrations/0028_auto_20240226_2234.py | 27 ----------------- src/lizaalert/courses/models.py | 15 ++++------ .../migrations/0008_auto_20240229_2149.py | 24 +++++++++++++++ src/lizaalert/users/models.py | 6 ++++ 6 files changed, 60 insertions(+), 53 deletions(-) rename src/lizaalert/courses/migrations/{0027_auto_20240225_1638.py => 0027_auto_20240229_2149.py} (82%) delete mode 100644 src/lizaalert/courses/migrations/0028_auto_20240226_2234.py create mode 100644 src/lizaalert/users/migrations/0008_auto_20240229_2149.py diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index ea8ec08e..0d896f75 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -11,7 +11,7 @@ CourseFaq, CourseKnowledge, CourseProgressStatus, - Direction, + Division, Knowledge, Lesson, LessonProgressStatus, @@ -66,10 +66,10 @@ def get_chapter_link(self, obj): get_chapter_link.short_description = "Глава" -class DirectionInline(admin.StackedInline): +class DivisionInline(admin.StackedInline): """Инлайн направления для отображения в главе.""" - model = Direction + model = Division min_num = 1 extra = 0 @@ -107,7 +107,7 @@ class CourseAdmin(admin.ModelAdmin): inlines = (CourseFaqInline, CourseKnowledgeInline, ChapterInline) list_filter = [ - "direction", + "division", ] model = Course list_display = ( @@ -117,7 +117,7 @@ class CourseAdmin(admin.ModelAdmin): "user_created", "created_at", "updated_at", - "direction", + "division", ) ordering = ("-updated_at",) empty_value_display = "-пусто-" @@ -241,8 +241,7 @@ class KnowledgeAdmin(admin.ModelAdmin): inlines = (CourseKnowledgeInline,) ordering = ("-updated_at",) - list_filter = ("direction",) - list_display = ("title", "author", "created_at", "updated_at", "direction") + list_display = ("title", "author", "created_at", "updated_at") @admin.register(Lesson) @@ -289,13 +288,21 @@ class SubscriptionAdmin(admin.ModelAdmin): ordering = ("-updated_at",) -@admin.register(Direction) -class DirectionAdmin(admin.ModelAdmin): - """Aдминка для Direction.""" +@admin.register(Division) +class DivisionAdmin(admin.ModelAdmin): + """Aдминка для Division.""" ordering = ("-updated_at",) list_display = ("title", "author", "created_at", "updated_at", "courses") + list_select_related = ("author",) @admin.display(description="Курсы") def courses(self, obj): - return list(obj.course_set.all()) + return list(obj.course_set.all().values_list("title", flat=True)) + + def get_queryset(self, request): + qs = self.model._default_manager.get_queryset().prefetch_related("course_set") + ordering = self.get_ordering(request) + if ordering: + qs = qs.order_by(*ordering) + return qs diff --git a/src/lizaalert/courses/migrations/0027_auto_20240225_1638.py b/src/lizaalert/courses/migrations/0027_auto_20240229_2149.py similarity index 82% rename from src/lizaalert/courses/migrations/0027_auto_20240225_1638.py rename to src/lizaalert/courses/migrations/0027_auto_20240229_2149.py index 438be86c..000889d1 100644 --- a/src/lizaalert/courses/migrations/0027_auto_20240225_1638.py +++ b/src/lizaalert/courses/migrations/0027_auto_20240229_2149.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.20 on 2024-02-25 13:38 +# Generated by Django 3.2.20 on 2024-02-29 18:49 from django.conf import settings from django.db import migrations, models @@ -14,7 +14,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Direction', + name='Division', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created_at', models.DateTimeField(auto_now_add=True)), @@ -31,11 +31,11 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name='course', - name='direction', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.direction', verbose_name='Направление курса'), + name='division', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление курса'), ), migrations.AddConstraint( - model_name='direction', - constraint=models.UniqueConstraint(fields=('title',), name='unique_direction'), + model_name='division', + constraint=models.UniqueConstraint(fields=('title',), name='unique_division'), ), ] diff --git a/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py b/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py deleted file mode 100644 index 836e52e6..00000000 --- a/src/lizaalert/courses/migrations/0028_auto_20240226_2234.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 3.2.20 on 2024-02-26 19:34 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('courses', '0027_auto_20240225_1638'), - ] - - operations = [ - migrations.RemoveConstraint( - model_name='knowledge', - name='unique_knowledge', - ), - migrations.AddField( - model_name='knowledge', - name='direction', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.direction', verbose_name='Направление умения'), - ), - migrations.AddConstraint( - model_name='knowledge', - constraint=models.UniqueConstraint(fields=('title', 'direction'), name='unique_knowledge'), - ), - ] diff --git a/src/lizaalert/courses/models.py b/src/lizaalert/courses/models.py index f90ea698..713d9386 100644 --- a/src/lizaalert/courses/models.py +++ b/src/lizaalert/courses/models.py @@ -74,13 +74,10 @@ class Knowledge(TimeStampedModel): title = models.CharField(max_length=250, verbose_name="Название умения") description = models.CharField(max_length=1000, verbose_name="Описание умения") author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель умения") - direction = models.ForeignKey( - "courses.Direction", on_delete=models.PROTECT, verbose_name="Направление умения", null=True, blank=True - ) class Meta: constraints = [ - models.UniqueConstraint(fields=("title", "direction"), name="unique_knowledge"), + models.UniqueConstraint(fields=("title",), name="unique_knowledge"), ] verbose_name = "Умение" verbose_name_plural = "Умения" @@ -123,8 +120,8 @@ class CourseStatus(models.IntegerChoices): ) user_created = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель курса") status = models.IntegerField(verbose_name="статус курса", choices=CourseStatus.choices, default=CourseStatus.DRAFT) - direction = models.ForeignKey( - "courses.Direction", on_delete=models.PROTECT, verbose_name="Направление курса", null=True, blank=True + division = models.ForeignKey( + "courses.Division", on_delete=models.PROTECT, verbose_name="Направление курса", null=True, blank=True ) class Meta: @@ -597,15 +594,15 @@ def finish(self): self.save() -class Direction(TimeStampedModel): +class Division(TimeStampedModel): title = models.CharField(max_length=250, verbose_name="Название направления") description = models.CharField(max_length=1000, verbose_name="Описание направления") author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель направления") class Meta: - constraints = [models.UniqueConstraint(fields=["title"], name="unique_direction")] + constraints = [models.UniqueConstraint(fields=["title"], name="unique_division")] verbose_name = "Направление" verbose_name_plural = "Направления" def __str__(self): - return self.title + return f"" diff --git a/src/lizaalert/users/migrations/0008_auto_20240229_2149.py b/src/lizaalert/users/migrations/0008_auto_20240229_2149.py new file mode 100644 index 00000000..283e8e70 --- /dev/null +++ b/src/lizaalert/users/migrations/0008_auto_20240229_2149.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.20 on 2024-02-29 18:49 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0027_auto_20240229_2149'), + ('users', '0007_badge_badge_slug'), + ] + + operations = [ + migrations.AddField( + model_name='badge', + name='division', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление умения'), + ), + migrations.AddConstraint( + model_name='badge', + constraint=models.UniqueConstraint(fields=('name', 'division'), name='unique_badge'), + ), + ] diff --git a/src/lizaalert/users/models.py b/src/lizaalert/users/models.py index ce832edf..1fc17b93 100644 --- a/src/lizaalert/users/models.py +++ b/src/lizaalert/users/models.py @@ -163,8 +163,14 @@ class BadgeCategory(models.TextChoices): blank=True, verbose_name="Курс для получения", ) + division = models.ForeignKey( + "courses.Division", on_delete=models.PROTECT, verbose_name="Направление умения", null=True, blank=True + ) class Meta: + constraints = [ + models.UniqueConstraint(fields=("name", "division"), name="unique_badge"), + ] db_table = "badges" verbose_name = "Значок" verbose_name_plural = "Значки" From 0cea7ab0b11e5da61a9989bd6ef825e3a22791e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Sun, 3 Mar 2024 22:18:43 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20m2m=20=D0=B2=D0=BE=D0=BB=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80-=D0=BD=D0=B0=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5-=D1=83=D1=80=D0=BE=D0=B2=D0=B5=D0=BD=D1=8C=20ver.?= =?UTF-8?q?=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lizaalert/users/admin.py | 19 +++++++++++- .../migrations/0009_auto_20240303_2149.py | 29 +++++++++++++++++++ src/lizaalert/users/models.py | 29 +++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/lizaalert/users/migrations/0009_auto_20240303_2149.py diff --git a/src/lizaalert/users/admin.py b/src/lizaalert/users/admin.py index 8e894e10..bedd8d34 100644 --- a/src/lizaalert/users/admin.py +++ b/src/lizaalert/users/admin.py @@ -9,6 +9,7 @@ Level, Location, User, + UserDivisionLevel, UserRole, Volunteer, VolunteerBadge, @@ -36,6 +37,11 @@ class LevelAdmin(admin.ModelAdmin): inlines = [VolunteerLevelInline] +class UserDivisionLevelInline(admin.TabularInline): + model = UserDivisionLevel + extra = 1 + + class BadgeAdminForm(forms.ModelForm): class Meta: model = Badge @@ -102,7 +108,17 @@ def clean(self): class VolunteerAdmin(admin.ModelAdmin): - inlines = [VolunteerLevelInline, VolunteerBadgeInline] + inlines = [VolunteerLevelInline, VolunteerBadgeInline, UserDivisionLevelInline] + + +class UserDivisionLevelAdmin(admin.ModelAdmin): + list_display = ("__str__", "volunteer", "division", "level") + list_display_links = ("volunteer",) + list_filter = ( + "volunteer", + "division", + "level", + ) admin.site.register(User, CustomUserAdmin) @@ -113,3 +129,4 @@ class VolunteerAdmin(admin.ModelAdmin): admin.site.register(Department) admin.site.register(Badge, BadgeAdmin) admin.site.register(Level, LevelAdmin) +admin.site.register(UserDivisionLevel, UserDivisionLevelAdmin) diff --git a/src/lizaalert/users/migrations/0009_auto_20240303_2149.py b/src/lizaalert/users/migrations/0009_auto_20240303_2149.py new file mode 100644 index 00000000..c22b4cc8 --- /dev/null +++ b/src/lizaalert/users/migrations/0009_auto_20240303_2149.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.20 on 2024-03-03 18:49 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0027_auto_20240229_2149'), + ('users', '0008_auto_20240229_2149'), + ] + + operations = [ + migrations.CreateModel( + name='UserDivisionLevel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('division', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление умения')), + ('level', models.ForeignKey(default='novice', on_delete=django.db.models.deletion.PROTECT, to='users.level', verbose_name='Уровень умения')), + ('volunteer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='divisionlevels', to='users.volunteer', verbose_name='Волонтер')), + ], + ), + migrations.AddField( + model_name='volunteer', + name='divisionlevel', + field=models.ManyToManyField(blank=True, related_name='volunteers', through='users.UserDivisionLevel', to='courses.Division', verbose_name='Уровень умения'), + ), + ] diff --git a/src/lizaalert/users/models.py b/src/lizaalert/users/models.py index 1fc17b93..f787ba7f 100644 --- a/src/lizaalert/users/models.py +++ b/src/lizaalert/users/models.py @@ -302,6 +302,13 @@ class Volunteer(models.Model): ) created_at = models.DateTimeField("Дата и время создания запси", auto_now_add=True) updated_at = models.DateTimeField("Дата обновления записи", auto_now=True) + divisionlevel = models.ManyToManyField( + "courses.Division", + through="users.UserDivisionLevel", + blank=True, + related_name="volunteers", + verbose_name="Уровень умения", + ) class Meta: db_table = "volunteers" @@ -327,3 +334,25 @@ def create_default_volunteer_level(sender, instance, created, **kwargs): if not existing_record: VolunteerLevel.objects.create(volunteer=volunteer, level=beginner_level, confirmed=True) + + +class UserDivisionLevel(models.Model): + """Модель для связи пользователей, направлений и уровней.""" + + volunteer = models.ForeignKey( + Volunteer, + on_delete=models.PROTECT, + related_name="divisionlevels", + verbose_name="Волонтер", + ) + division = models.ForeignKey("courses.Division", on_delete=models.PROTECT, verbose_name="Направление умения") + level = models.ForeignKey( + Level, on_delete=models.PROTECT, verbose_name="Уровень умения", default=Level.LevelName.beginner + ) + + class Meta: + verbose_name = "Уровень волонтера по направлениям" + verbose_name_plural = "Уровни волонтеров по направлениям" + + def __str__(self): + return f"Уровень {self.volunteer.user} {self.level.name} в направлении {self.division.title}" From f89d2aea7b812792de589853a523302794bb77a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Tue, 5 Mar 2024 18:04:14 +0300 Subject: [PATCH 5/8] change 1 --- src/lizaalert/courses/admin.py | 9 +++++++-- src/lizaalert/users/models.py | 15 ++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index 0d896f75..4b12b892 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -293,12 +293,13 @@ class DivisionAdmin(admin.ModelAdmin): """Aдминка для Division.""" ordering = ("-updated_at",) - list_display = ("title", "author", "created_at", "updated_at", "courses") + list_display = ("title", "author", "updated_at", "courses") + exclude = ('author',) list_select_related = ("author",) @admin.display(description="Курсы") def courses(self, obj): - return list(obj.course_set.all().values_list("title", flat=True)) + return str(list(obj.course_set.all().values_list("title", flat=True))).split('\\n') def get_queryset(self, request): qs = self.model._default_manager.get_queryset().prefetch_related("course_set") @@ -306,3 +307,7 @@ def get_queryset(self, request): if ordering: qs = qs.order_by(*ordering) return qs + + def save_model(self, request, obj, form, change): + obj.author = request.user + obj.save() diff --git a/src/lizaalert/users/models.py b/src/lizaalert/users/models.py index f787ba7f..92602750 100644 --- a/src/lizaalert/users/models.py +++ b/src/lizaalert/users/models.py @@ -164,13 +164,10 @@ class BadgeCategory(models.TextChoices): verbose_name="Курс для получения", ) division = models.ForeignKey( - "courses.Division", on_delete=models.PROTECT, verbose_name="Направление умения", null=True, blank=True + "courses.Division", on_delete=models.SET_NULL, verbose_name="Направление умения", null=True, blank=True ) class Meta: - constraints = [ - models.UniqueConstraint(fields=("name", "division"), name="unique_badge"), - ] db_table = "badges" verbose_name = "Значок" verbose_name_plural = "Значки" @@ -302,7 +299,7 @@ class Volunteer(models.Model): ) created_at = models.DateTimeField("Дата и время создания запси", auto_now_add=True) updated_at = models.DateTimeField("Дата обновления записи", auto_now=True) - divisionlevel = models.ManyToManyField( + divisionlevels = models.ManyToManyField( "courses.Division", through="users.UserDivisionLevel", blank=True, @@ -341,13 +338,13 @@ class UserDivisionLevel(models.Model): volunteer = models.ForeignKey( Volunteer, - on_delete=models.PROTECT, - related_name="divisionlevels", + on_delete=models.CASCADE, + related_name="divisionlevel", verbose_name="Волонтер", ) - division = models.ForeignKey("courses.Division", on_delete=models.PROTECT, verbose_name="Направление умения") + division = models.ForeignKey("courses.Division", on_delete=models.CASCADE, verbose_name="Направление умения") level = models.ForeignKey( - Level, on_delete=models.PROTECT, verbose_name="Уровень умения", default=Level.LevelName.beginner + Level, on_delete=models.CASCADE, verbose_name="Уровень умения", default=Level.LevelName.beginner ) class Meta: From e8e2829b3d2f9eb17cbf2de0d949ce0a0b19d1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Tue, 5 Mar 2024 23:31:23 +0300 Subject: [PATCH 6/8] ver 3.0 --- src/lizaalert/courses/admin.py | 8 +++- .../migrations/0010_auto_20240305_2329.py | 48 +++++++++++++++++++ src/lizaalert/users/models.py | 2 +- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/lizaalert/users/migrations/0010_auto_20240305_2329.py diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index 4b12b892..13db2b4c 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -294,12 +294,16 @@ class DivisionAdmin(admin.ModelAdmin): ordering = ("-updated_at",) list_display = ("title", "author", "updated_at", "courses") - exclude = ('author',) + exclude = ("author",) list_select_related = ("author",) @admin.display(description="Курсы") def courses(self, obj): - return str(list(obj.course_set.all().values_list("title", flat=True))).split('\\n') + courses_list = obj.course_set.all().values_list("title", flat=True) + result = "" + for course in courses_list: + result += course + "\n" + return result def get_queryset(self, request): qs = self.model._default_manager.get_queryset().prefetch_related("course_set") diff --git a/src/lizaalert/users/migrations/0010_auto_20240305_2329.py b/src/lizaalert/users/migrations/0010_auto_20240305_2329.py new file mode 100644 index 00000000..3c0d1a75 --- /dev/null +++ b/src/lizaalert/users/migrations/0010_auto_20240305_2329.py @@ -0,0 +1,48 @@ +# Generated by Django 3.2.20 on 2024-03-05 20:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0027_auto_20240229_2149'), + ('users', '0009_auto_20240303_2149'), + ] + + operations = [ + migrations.AlterModelOptions( + name='userdivisionlevel', + options={'verbose_name': 'Уровень волонтера по направлениям', 'verbose_name_plural': 'Уровни волонтеров по направлениям'}, + ), + migrations.RemoveConstraint( + model_name='badge', + name='unique_badge', + ), + migrations.RenameField( + model_name='volunteer', + old_name='divisionlevel', + new_name='divisionlevels', + ), + migrations.AlterField( + model_name='badge', + name='division', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.division', verbose_name='Направление умения'), + ), + migrations.AlterField( + model_name='userdivisionlevel', + name='division', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.division', verbose_name='Направление умения'), + ), + migrations.AlterField( + model_name='userdivisionlevel', + name='level', + field=models.ForeignKey(default='novice', on_delete=django.db.models.deletion.CASCADE, to='users.level', verbose_name='Уровень умения'), + ), + migrations.AlterField( + model_name='userdivisionlevel', + name='volunteer', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='divisionlevel', to='users.volunteer', verbose_name='Волонтер'), + ), + ] diff --git a/src/lizaalert/users/models.py b/src/lizaalert/users/models.py index 92602750..880ec641 100644 --- a/src/lizaalert/users/models.py +++ b/src/lizaalert/users/models.py @@ -352,4 +352,4 @@ class Meta: verbose_name_plural = "Уровни волонтеров по направлениям" def __str__(self): - return f"Уровень {self.volunteer.user} {self.level.name} в направлении {self.division.title}" + return f"Направление {self.division.title}" From 1986feecabae8fe535fd667832123219aa0dd3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Tue, 12 Mar 2024 22:25:56 +0300 Subject: [PATCH 7/8] ver 4.0 --- src/lizaalert/courses/admin.py | 15 +----- src/lizaalert/courses/models.py | 2 + src/lizaalert/users/admin.py | 2 +- .../migrations/0009_auto_20240303_2149.py | 29 ---------- .../migrations/0009_auto_20240312_2151.py | 54 +++++++++++++++++++ .../migrations/0010_auto_20240305_2329.py | 48 ----------------- src/lizaalert/users/models.py | 8 +-- 7 files changed, 64 insertions(+), 94 deletions(-) delete mode 100644 src/lizaalert/users/migrations/0009_auto_20240303_2149.py create mode 100644 src/lizaalert/users/migrations/0009_auto_20240312_2151.py delete mode 100644 src/lizaalert/users/migrations/0010_auto_20240305_2329.py diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index 13db2b4c..da9a9e90 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -66,14 +66,6 @@ def get_chapter_link(self, obj): get_chapter_link.short_description = "Глава" -class DivisionInline(admin.StackedInline): - """Инлайн направления для отображения в главе.""" - - model = Division - min_num = 1 - extra = 0 - - @admin.register(Cohort) class CohortAdmin(admin.ModelAdmin): """ @@ -299,11 +291,8 @@ class DivisionAdmin(admin.ModelAdmin): @admin.display(description="Курсы") def courses(self, obj): - courses_list = obj.course_set.all().values_list("title", flat=True) - result = "" - for course in courses_list: - result += course + "\n" - return result + """Показывает курсы по этим направлениям.""" + return [[course.title] for course in obj.course_set.all()] def get_queryset(self, request): qs = self.model._default_manager.get_queryset().prefetch_related("course_set") diff --git a/src/lizaalert/courses/models.py b/src/lizaalert/courses/models.py index 713d9386..ccd11ba4 100644 --- a/src/lizaalert/courses/models.py +++ b/src/lizaalert/courses/models.py @@ -595,6 +595,8 @@ def finish(self): class Division(TimeStampedModel): + """Модель направления курсов.""" + title = models.CharField(max_length=250, verbose_name="Название направления") description = models.CharField(max_length=1000, verbose_name="Описание направления") author = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Создатель направления") diff --git a/src/lizaalert/users/admin.py b/src/lizaalert/users/admin.py index bedd8d34..3dae9e6b 100644 --- a/src/lizaalert/users/admin.py +++ b/src/lizaalert/users/admin.py @@ -112,7 +112,7 @@ class VolunteerAdmin(admin.ModelAdmin): class UserDivisionLevelAdmin(admin.ModelAdmin): - list_display = ("__str__", "volunteer", "division", "level") + list_display = ("id", "volunteer", "division", "level") list_display_links = ("volunteer",) list_filter = ( "volunteer", diff --git a/src/lizaalert/users/migrations/0009_auto_20240303_2149.py b/src/lizaalert/users/migrations/0009_auto_20240303_2149.py deleted file mode 100644 index c22b4cc8..00000000 --- a/src/lizaalert/users/migrations/0009_auto_20240303_2149.py +++ /dev/null @@ -1,29 +0,0 @@ -# Generated by Django 3.2.20 on 2024-03-03 18:49 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('courses', '0027_auto_20240229_2149'), - ('users', '0008_auto_20240229_2149'), - ] - - operations = [ - migrations.CreateModel( - name='UserDivisionLevel', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('division', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление умения')), - ('level', models.ForeignKey(default='novice', on_delete=django.db.models.deletion.PROTECT, to='users.level', verbose_name='Уровень умения')), - ('volunteer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='divisionlevels', to='users.volunteer', verbose_name='Волонтер')), - ], - ), - migrations.AddField( - model_name='volunteer', - name='divisionlevel', - field=models.ManyToManyField(blank=True, related_name='volunteers', through='users.UserDivisionLevel', to='courses.Division', verbose_name='Уровень умения'), - ), - ] diff --git a/src/lizaalert/users/migrations/0009_auto_20240312_2151.py b/src/lizaalert/users/migrations/0009_auto_20240312_2151.py new file mode 100644 index 00000000..638bf208 --- /dev/null +++ b/src/lizaalert/users/migrations/0009_auto_20240312_2151.py @@ -0,0 +1,54 @@ +# Generated by Django 3.2.20 on 2024-03-12 18:51 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('courses', '0027_auto_20240229_2149'), + ('users', '0008_auto_20240229_2149'), + ] + + operations = [ + migrations.CreateModel( + name='UserDivisionLevel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + options={ + 'verbose_name': 'Уровень волонтера по направлениям', + 'verbose_name_plural': 'Уровни волонтеров по направлениям', + }, + ), + migrations.RemoveConstraint( + model_name='badge', + name='unique_badge', + ), + migrations.AlterField( + model_name='badge', + name='division', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.division', verbose_name='Направление умения'), + ), + migrations.AddField( + model_name='userdivisionlevel', + name='division', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.division', verbose_name='Направление умения'), + ), + migrations.AddField( + model_name='userdivisionlevel', + name='level', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.level', verbose_name='Уровень умения'), + ), + migrations.AddField( + model_name='userdivisionlevel', + name='volunteer', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='division_level', to='users.volunteer', verbose_name='Волонтер'), + ), + migrations.AddField( + model_name='volunteer', + name='division_levels', + field=models.ManyToManyField(blank=True, related_name='volunteers', through='users.UserDivisionLevel', to='courses.Division', verbose_name='Уровень умения'), + ), + ] diff --git a/src/lizaalert/users/migrations/0010_auto_20240305_2329.py b/src/lizaalert/users/migrations/0010_auto_20240305_2329.py deleted file mode 100644 index 3c0d1a75..00000000 --- a/src/lizaalert/users/migrations/0010_auto_20240305_2329.py +++ /dev/null @@ -1,48 +0,0 @@ -# Generated by Django 3.2.20 on 2024-03-05 20:29 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('courses', '0027_auto_20240229_2149'), - ('users', '0009_auto_20240303_2149'), - ] - - operations = [ - migrations.AlterModelOptions( - name='userdivisionlevel', - options={'verbose_name': 'Уровень волонтера по направлениям', 'verbose_name_plural': 'Уровни волонтеров по направлениям'}, - ), - migrations.RemoveConstraint( - model_name='badge', - name='unique_badge', - ), - migrations.RenameField( - model_name='volunteer', - old_name='divisionlevel', - new_name='divisionlevels', - ), - migrations.AlterField( - model_name='badge', - name='division', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.division', verbose_name='Направление умения'), - ), - migrations.AlterField( - model_name='userdivisionlevel', - name='division', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.division', verbose_name='Направление умения'), - ), - migrations.AlterField( - model_name='userdivisionlevel', - name='level', - field=models.ForeignKey(default='novice', on_delete=django.db.models.deletion.CASCADE, to='users.level', verbose_name='Уровень умения'), - ), - migrations.AlterField( - model_name='userdivisionlevel', - name='volunteer', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='divisionlevel', to='users.volunteer', verbose_name='Волонтер'), - ), - ] diff --git a/src/lizaalert/users/models.py b/src/lizaalert/users/models.py index 880ec641..ca8337b4 100644 --- a/src/lizaalert/users/models.py +++ b/src/lizaalert/users/models.py @@ -299,7 +299,7 @@ class Volunteer(models.Model): ) created_at = models.DateTimeField("Дата и время создания запси", auto_now_add=True) updated_at = models.DateTimeField("Дата обновления записи", auto_now=True) - divisionlevels = models.ManyToManyField( + division_levels = models.ManyToManyField( "courses.Division", through="users.UserDivisionLevel", blank=True, @@ -339,12 +339,14 @@ class UserDivisionLevel(models.Model): volunteer = models.ForeignKey( Volunteer, on_delete=models.CASCADE, - related_name="divisionlevel", + related_name="division_level", verbose_name="Волонтер", ) division = models.ForeignKey("courses.Division", on_delete=models.CASCADE, verbose_name="Направление умения") level = models.ForeignKey( - Level, on_delete=models.CASCADE, verbose_name="Уровень умения", default=Level.LevelName.beginner + Level, + on_delete=models.CASCADE, + verbose_name="Уровень умения", ) class Meta: From a9d4a4576d5fda99163b0ed723e67988a241c413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D0=BC=D0=B0=D0=BD=20=D0=9B=D0=B5=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=8C=D0=B5=D0=B2?= Date: Wed, 13 Mar 2024 23:53:38 +0300 Subject: [PATCH 8/8] ver 5.0 --- src/lizaalert/courses/admin.py | 14 ++----- .../migrations/0027_auto_20240229_2149.py | 41 ------------------- .../migrations/0008_auto_20240229_2149.py | 24 ----------- ...312_2151.py => 0010_auto_20240313_2336.py} | 38 +++++------------ 4 files changed, 14 insertions(+), 103 deletions(-) delete mode 100644 src/lizaalert/courses/migrations/0027_auto_20240229_2149.py delete mode 100644 src/lizaalert/users/migrations/0008_auto_20240229_2149.py rename src/lizaalert/users/migrations/{0009_auto_20240312_2151.py => 0010_auto_20240313_2336.py} (52%) diff --git a/src/lizaalert/courses/admin.py b/src/lizaalert/courses/admin.py index fb9cfcf0..3d43665f 100644 --- a/src/lizaalert/courses/admin.py +++ b/src/lizaalert/courses/admin.py @@ -258,11 +258,7 @@ class KnowledgeAdmin(BaseAdmin): inlines = (CourseKnowledgeInline,) ordering = ("-updated_at",) - list_display = ( - "title", - "author", - "updated_at", - ) + list_display = ("title", "author", "created_at", "updated_at") @admin.register(Lesson) @@ -310,7 +306,7 @@ class SubscriptionAdmin(BaseAdmin): @admin.register(Division) -class DivisionAdmin(admin.ModelAdmin): +class DivisionAdmin(BaseAdmin): """Aдминка для Division.""" ordering = ("-updated_at",) @@ -324,11 +320,7 @@ def courses(self, obj): return [[course.title] for course in obj.course_set.all()] def get_queryset(self, request): - qs = self.model._default_manager.get_queryset().prefetch_related("course_set") - ordering = self.get_ordering(request) - if ordering: - qs = qs.order_by(*ordering) - return qs + return super().get_queryset(request).prefetch_related("course_set") def save_model(self, request, obj, form, change): obj.author = request.user diff --git a/src/lizaalert/courses/migrations/0027_auto_20240229_2149.py b/src/lizaalert/courses/migrations/0027_auto_20240229_2149.py deleted file mode 100644 index 000889d1..00000000 --- a/src/lizaalert/courses/migrations/0027_auto_20240229_2149.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 3.2.20 on 2024-02-29 18:49 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('courses', '0026_alter_lesson_lesson_type'), - ] - - operations = [ - migrations.CreateModel( - name='Division', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created_at', models.DateTimeField(auto_now_add=True)), - ('updated_at', models.DateTimeField(auto_now=True, db_index=True)), - ('deleted_at', models.DateTimeField(blank=True, null=True)), - ('title', models.CharField(max_length=250, verbose_name='Название направления')), - ('description', models.CharField(max_length=1000, verbose_name='Описание направления')), - ('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Создатель направления')), - ], - options={ - 'verbose_name': 'Направление', - 'verbose_name_plural': 'Направления', - }, - ), - migrations.AddField( - model_name='course', - name='division', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление курса'), - ), - migrations.AddConstraint( - model_name='division', - constraint=models.UniqueConstraint(fields=('title',), name='unique_division'), - ), - ] diff --git a/src/lizaalert/users/migrations/0008_auto_20240229_2149.py b/src/lizaalert/users/migrations/0008_auto_20240229_2149.py deleted file mode 100644 index 283e8e70..00000000 --- a/src/lizaalert/users/migrations/0008_auto_20240229_2149.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 3.2.20 on 2024-02-29 18:49 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('courses', '0027_auto_20240229_2149'), - ('users', '0007_badge_badge_slug'), - ] - - operations = [ - migrations.AddField( - model_name='badge', - name='division', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='courses.division', verbose_name='Направление умения'), - ), - migrations.AddConstraint( - model_name='badge', - constraint=models.UniqueConstraint(fields=('name', 'division'), name='unique_badge'), - ), - ] diff --git a/src/lizaalert/users/migrations/0009_auto_20240312_2151.py b/src/lizaalert/users/migrations/0010_auto_20240313_2336.py similarity index 52% rename from src/lizaalert/users/migrations/0009_auto_20240312_2151.py rename to src/lizaalert/users/migrations/0010_auto_20240313_2336.py index 638bf208..6d8a1a33 100644 --- a/src/lizaalert/users/migrations/0009_auto_20240312_2151.py +++ b/src/lizaalert/users/migrations/0010_auto_20240313_2336.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.20 on 2024-03-12 18:51 +# Generated by Django 3.2.23 on 2024-03-13 20:36 from django.db import migrations, models import django.db.models.deletion @@ -7,45 +7,29 @@ class Migration(migrations.Migration): dependencies = [ - ('courses', '0027_auto_20240229_2149'), - ('users', '0008_auto_20240229_2149'), + ('courses', '0028_auto_20240313_1341'), + ('users', '0009_auto_20240313_1341'), ] operations = [ + migrations.AlterField( + model_name='badge', + name='division', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.division', verbose_name='Направление умения'), + ), migrations.CreateModel( name='UserDivisionLevel', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('division', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.division', verbose_name='Направление умения')), + ('level', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.level', verbose_name='Уровень умения')), + ('volunteer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='division_level', to='users.volunteer', verbose_name='Волонтер')), ], options={ 'verbose_name': 'Уровень волонтера по направлениям', 'verbose_name_plural': 'Уровни волонтеров по направлениям', }, ), - migrations.RemoveConstraint( - model_name='badge', - name='unique_badge', - ), - migrations.AlterField( - model_name='badge', - name='division', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='courses.division', verbose_name='Направление умения'), - ), - migrations.AddField( - model_name='userdivisionlevel', - name='division', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.division', verbose_name='Направление умения'), - ), - migrations.AddField( - model_name='userdivisionlevel', - name='level', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.level', verbose_name='Уровень умения'), - ), - migrations.AddField( - model_name='userdivisionlevel', - name='volunteer', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='division_level', to='users.volunteer', verbose_name='Волонтер'), - ), migrations.AddField( model_name='volunteer', name='division_levels',