<commit_before>from django.contrib.gis import admin
from django import forms
from django.utils.translation import gettext_lazy as _

from treebeard.forms import movenodeform_factory

from froide.helper.admin_utils import ForeignKeyFilter
from froide.helper.forms import get_fk_raw_id_widget

from .models import GeoRegion


class GeoRegionAdminForm(movenodeform_factory(GeoRegion)):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        widget = get_fk_raw_id_widget(GeoRegion, admin.site, field_name='id')
        self.fields['_ref_node_id'] = forms.IntegerField(
            required=False, label=_("Relative to"),
            widget=widget
        )

    @classmethod
    def mk_dropdown_tree(cls, model, for_node=None):
        return []


class GeoRegionMixin(object):
    form = GeoRegionAdminForm

    search_fields = ['name', 'region_identifier']
    list_display = ('name', 'kind', 'kind_detail', 'region_identifier')
    list_filter = (
        'kind', 'kind_detail',
        ('part_of', ForeignKeyFilter),
    )
    raw_id_fields = ('part_of',)
    readonly_fields = ('depth', 'numchild', 'path')


class GeoRegionAdmin(GeoRegionMixin, admin.GeoModelAdmin):
    pass


admin.site.register(GeoRegion, GeoRegionAdmin)<commit_msg>Search region_identifier with startswith in admin<commit_after>from django.contrib.gis import admin
from django import forms
from django.utils.translation import gettext_lazy as _

from treebeard.forms import movenodeform_factory

from froide.helper.admin_utils import ForeignKeyFilter
from froide.helper.forms import get_fk_raw_id_widget

from .models import GeoRegion


class GeoRegionAdminForm(movenodeform_factory(GeoRegion)):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        widget = get_fk_raw_id_widget(GeoRegion, admin.site, field_name='id')
        self.fields['_ref_node_id'] = forms.IntegerField(
            required=False, label=_("Relative to"),
            widget=widget
        )

    @classmethod
    def mk_dropdown_tree(cls, model, for_node=None):
        return []


class GeoRegionMixin(object):
    form = GeoRegionAdminForm

    search_fields = ['name', '^region_identifier']
    list_display = ('name', 'kind', 'kind_detail', 'region_identifier')
    list_filter = (
        'kind', 'kind_detail',
        ('part_of', ForeignKeyFilter),
    )
    raw_id_fields = ('part_of',)
    readonly_fields = ('depth', 'numchild', 'path')


class GeoRegionAdmin(GeoRegionMixin, admin.GeoModelAdmin):
    pass


admin.site.register(GeoRegion, GeoRegionAdmin)
{'fraction_non_alphanumeric': 0.10768043226553455, 'fraction_numerical': 0.0, 'mean_word_length': 4.122529644268774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5184513', 'n_tokens_mistral': 819, 'n_tokens_neox': 791, 'n_words': 168}