<commit_before>import inspect
import sys
from django.contrib import admin
from django.utils.html import format_html

from chat import models
from chat.models import UserJoinedInfo
from chat.settings import STATIC_URL

exclude_auto = ('UserJoinedInfo',)
model_classes = (class_name[1] for class_name in inspect.getmembers(sys.modules[models.__name__], inspect.isclass)
					if class_name[1].__module__ == models.__name__ and class_name[0] not in exclude_auto)
for model in model_classes:
	fields = [field.name for field in model._meta.fields if field.name not in ("password")]
	admin.site.register(model, type('SubClass', (admin.ModelAdmin,), {'fields': fields, 'list_display': fields}))


@admin.register(UserJoinedInfo)
class UserLocation(admin.ModelAdmin):
	list_display = ['username', 'country', 'region', 'city', 'provider', 'time', 'ip']

	def region(self, instance):
		return instance.ip.region

	def city(self, instance):
		return instance.ip.city
<commit_msg>Added filters to admin UserJoinedInfo<commit_after>import inspect
import sys
from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.db.models import Count
from django.utils.html import format_html

from chat import models
from chat.models import UserJoinedInfo
from chat.settings import STATIC_URL

exclude_auto = ('UserJoinedInfo',)
model_classes = (class_name[1] for class_name in inspect.getmembers(sys.modules[models.__name__], inspect.isclass)
					if class_name[1].__module__ == models.__name__ and class_name[0] not in exclude_auto)
for model in model_classes:
	fields = [field.name for field in model._meta.fields if field.name not in ("password")]
	admin.site.register(model, type('SubClass', (admin.ModelAdmin,), {'fields': fields, 'list_display': fields}))


class RegisteredFilter(SimpleListFilter):
	title = 'if registered'
	parameter_name = 'registered'

	def lookups(self, request, model_admin):
		return ((False, ('Registered')), (True, 'Anonymous'))

	def queryset(self, request, queryset):
		if self.value():
			return queryset.filter(user__isnull=self.value() == 'True')
		else:
			return queryset


class CountryFilter(SimpleListFilter):
	title = 'country'
	parameter_name = 'country'

	def lookups(self, request, model_admin):
		query_set = model_admin.model.objects.values('ip__country').annotate(count=Count('ip__country'))
		return [(c['ip__country'], '%s(%s)' % (c['ip__country'], c['count'])) for c in query_set]

	def queryset(self, request, queryset):
		if self.value():
			return queryset.filter(ip__country=self.value())
		else:
			return queryset


@admin.register(UserJoinedInfo)
class UserLocation(admin.ModelAdmin):
	list_display = ['username', 'country', 'region', 'city', 'provider', 'time', 'ip']
	list_filter = (RegisteredFilter, CountryFilter, 'time')

	def region(self, instance):
		return instance.ip.region

	def city(self, instance):
		return instance.ip.city

{'fraction_non_alphanumeric': 0.1254295532646048, 'fraction_numerical': 0.002061855670103093, 'mean_word_length': 6.134803921568627, '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': '173085', 'n_tokens_mistral': 922, 'n_tokens_neox': 877, 'n_words': 244}