Cascade categories on delete

This commit is contained in:
FinnStutzenstein 2019-08-05 13:11:32 +02:00
parent 32bec58333
commit d182c2c36f
4 changed files with 29 additions and 5 deletions

View File

@ -158,7 +158,7 @@ export class CategoryDetailComponent extends BaseViewComponent implements OnInit
* Click handler to delete a category
*/
public async onDeleteButton(): Promise<void> {
const title = this.translate.instant('Are you sure you want to delete this category?');
const title = this.translate.instant('Are you sure you want to delete this category and all subcategories?');
const content = this.selectedCategory.prefixedName;
if (await this.promptService.open(title, content)) {
await this.repo.delete(this.selectedCategory);

View File

@ -80,7 +80,7 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit {
this.dataSource = new MatTableDataSource();
this.repo.getViewModelListObservable().subscribe(viewCategories => {
if (viewCategories && viewCategories.length && this.dataSource) {
if (viewCategories && this.dataSource) {
this.dataSource.data = viewCategories;
}
});

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.3 on 2019-08-05 10:50
from django.db import migrations, models
import openslides.utils.models
class Migration(migrations.Migration):
dependencies = [("motions", "0031_state_css_classes_2")]
operations = [
migrations.AlterField(
model_name="category",
name="parent",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=openslides.utils.models.CASCADE_AND_AUTOUPDATE,
related_name="children",
to="motions.Category",
),
)
]

View File

@ -804,14 +804,14 @@ class Category(RESTModelMixin, models.Model):
"""Name of the category."""
prefix = models.CharField(blank=True, max_length=32)
"""Prefix of the category.
"""
Prefix of the category.
Used to build the identifier of a motion.
"""
parent = models.ForeignKey(
"self",
on_delete=SET_NULL_AND_AUTOUPDATE,
on_delete=CASCADE_AND_AUTOUPDATE,
null=True,
blank=True,
related_name="children",