Skip to content

Commit

Permalink
broader_concept added but messed up migrations #8
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Nov 5, 2021
1 parent 583a562 commit 8cabe3d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 33 deletions.
17 changes: 16 additions & 1 deletion archiv/admin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
# generated by appcreator
from django.contrib import admin
from mptt.admin import DraggableMPTTAdmin

from . models import (
Archiv,
Bibliography,
Glossary,
Place,
Tablet
)


@admin.register(Glossary)
class GlossaryAdmin(DraggableMPTTAdmin):
model = Glossary

list_filter = (
('glossary_collection'),
('broader_concept', admin.RelatedOnlyFieldListFilter),
)
search_fields = ['pref_label']
autocomplete_fields = ['broader_concept']


admin.site.register(Archiv)
admin.site.register(Bibliography)
admin.site.register(Glossary)
admin.site.register(Place)
admin.site.register(Tablet)
11 changes: 5 additions & 6 deletions archiv/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ class GlossaryListFilter(django_filters.FilterSet):
help_text=Glossary._meta.get_field('pref_label').help_text,
label=Glossary._meta.get_field('pref_label').verbose_name
)
hierarchy = django_filters.CharFilter(
glossary_collection = django_filters.CharFilter(
lookup_expr='icontains',
help_text=Glossary._meta.get_field('hierarchy').help_text,
label=Glossary._meta.get_field('hierarchy').verbose_name
help_text=Glossary._meta.get_field('glossary_collection').help_text,
label=Glossary._meta.get_field('glossary_collection').verbose_name
)
title = django_filters.CharFilter(
lookup_expr='icontains',
Expand All @@ -188,10 +188,9 @@ class Meta:
'legacy_id',
'legacy_pk',
'pref_label',
'hierarchy',
'type',
'glossary_collection',
'title',
]
]


class PlaceListFilter(django_filters.FilterSet):
Expand Down
4 changes: 1 addition & 3 deletions archiv/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, *args, **kwargs):
Accordion(
AccordionGroup(
'Advanced search',

'legacy_pk',
'name',
'part_of',
Expand Down Expand Up @@ -139,10 +138,9 @@ def __init__(self, *args, **kwargs):
Accordion(
AccordionGroup(
'Advanced search',

'legacy_pk',
'pref_label',
'hierarchy',
'glossary_collection',
'type',
'title',
css_id="more"
Expand Down
22 changes: 22 additions & 0 deletions archiv/migrations/0008_auto_20211105_0913.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.7 on 2021-11-05 09:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('archiv', '0007_auto_20211015_1512'),
]

operations = [
migrations.RemoveField(
model_name='glossary',
name='hierarchy',
),
migrations.AddField(
model_name='glossary',
name='glossary_collection',
field=models.CharField(blank=True, help_text='Collection to group Glossary entries', max_length=250, verbose_name='Collection'),
),
]
52 changes: 52 additions & 0 deletions archiv/migrations/0009_auto_20211105_0923.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 3.2.7 on 2021-11-05 09:23

from django.db import migrations, models
import django.db.models.deletion
import mptt.fields


class Migration(migrations.Migration):

dependencies = [
('archiv', '0008_auto_20211105_0913'),
]

operations = [
migrations.AlterModelOptions(
name='glossary',
options={},
),
migrations.RemoveField(
model_name='glossary',
name='type',
),
migrations.AddField(
model_name='glossary',
name='broader_concept',
field=mptt.fields.TreeForeignKey(blank=True, help_text='Concept with a broader meaning that this concept inherits from', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='narrower_concepts', to='archiv.glossary', verbose_name='skos:broader'),
),
migrations.AddField(
model_name='glossary',
name='level',
field=models.PositiveIntegerField(default=1, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='glossary',
name='lft',
field=models.PositiveIntegerField(default=1, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='glossary',
name='rght',
field=models.PositiveIntegerField(default=1, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='glossary',
name='tree_id',
field=models.PositiveIntegerField(db_index=True, default=1, editable=False),
preserve_default=False,
),
]
41 changes: 18 additions & 23 deletions archiv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from django.db import models
from django.urls import reverse


from browsing.browsing_utils import model_to_dict

from mptt.models import MPTTModel, TreeForeignKey

def set_extra(self, **kwargs):
self.extra = kwargs
Expand All @@ -16,7 +15,7 @@ def set_extra(self, **kwargs):


class Archiv(models.Model):
### Archiv ###
""" Archiv """
legacy_id = models.CharField(
max_length=300, blank=True,
verbose_name="Legacy ID"
Expand Down Expand Up @@ -141,7 +140,7 @@ def get_prev(self):


class Bibliography(models.Model):
### Bibliography ###
""" Bibliography """
legacy_id = models.CharField(
max_length=300, blank=True,
verbose_name="Legacy ID"
Expand Down Expand Up @@ -342,8 +341,8 @@ def get_prev(self):
return False


class Glossary(models.Model):
### Glossary ###
class Glossary(MPTTModel):
""" Glossary """
legacy_id = models.CharField(
max_length=300, blank=True,
verbose_name="Legacy ID"
Expand All @@ -365,22 +364,18 @@ class Glossary(models.Model):
is_public=True,
data_lookup="Label",
)
hierarchy = models.CharField(
glossary_collection = models.CharField(
max_length=250,
blank=True,
verbose_name="Hierarchy",
help_text="whatever",
).set_extra(
is_public=True,
data_lookup="Hierarchy",
verbose_name="Collection",
help_text="Collection to group Glossary entries"
)
type = models.IntegerField(
blank=True, null=True,
verbose_name="Type",
help_text="whatever",
).set_extra(
is_public=True,
data_lookup="Type",
broader_concept = TreeForeignKey(
'self',
verbose_name="skos:broader",
blank=True, null=True, on_delete=models.SET_NULL,
related_name="narrower_concepts",
help_text="Concept with a broader meaning that this concept inherits from"
)
title = models.CharField(
max_length=250,
Expand All @@ -399,8 +394,8 @@ class Glossary(models.Model):
is_public=True
)

class Meta:

class MPTTMeta:
parent_attr = 'broader_concept'
ordering = [
'pref_label',
]
Expand Down Expand Up @@ -464,7 +459,7 @@ def get_prev(self):


class Place(models.Model):
### Place ###
""" Place """
legacy_id = models.CharField(
max_length=300, blank=True,
verbose_name="Legacy ID"
Expand Down Expand Up @@ -580,7 +575,7 @@ def get_prev(self):


class Tablet(models.Model):
### Tablet ###
""" Tablet """
legacy_id = models.CharField(
max_length=300, blank=True,
verbose_name="Legacy ID"
Expand Down
1 change: 1 addition & 0 deletions djangobaseproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'crispy_forms',
'django_filters',
'django_tables2',
'mptt',
'browsing',
'infos',
'webpage',
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ acdh-django-browsing
acdh-django-netvis==3.1.0
acdh-xml-pyutils==0.4.0
Django==3.2.7
django-mptt>=0.13.4
jinja2>=3.0.1
pandas==1.3.3
psycopg2-binary==2.9.1
Expand Down

0 comments on commit 8cabe3d

Please sign in to comment.