Skip to content
Snippets Groups Projects
Commit 23a4d244 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'admin-types' into 'master'

Display only available element types in admin

See merge request !718
parents feab1266 f5b1d064
No related branches found
No related tags found
1 merge request!718Display only available element types in admin
......@@ -58,6 +58,18 @@ class ElementAdmin(admin.ModelAdmin):
search_fields = ('name', )
inlines = (MetaDataInline, ClassificationInline)
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'type':
# Only display types available on the element's corpus
# It would make no sense to pick a type from another corpus
# Display all elements on creation, as we do not know yet the corpus
element_id = request.resolver_match.kwargs.get('object_id')
if element_id:
element = self.get_object(request, element_id)
kwargs['queryset'] = ElementType.objects.filter(corpus=element.corpus).order_by('display_name')
return super().formfield_for_foreignkey(db_field, request, **kwargs)
class TranscriptionAdmin(admin.ModelAdmin):
list_display = ('id', 'text', 'score', 'element', )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment