Skip to content

Commit

Permalink
chore: Add admin models for flag, experiment, and cohorts (#18579)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkakkar authored Nov 14, 2023
1 parent 67dbe09 commit 550bb8d
Showing 1 changed file with 95 additions and 1 deletion.
96 changes: 95 additions & 1 deletion posthog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
PluginAttachment,
PluginConfig,
Team,
Cohort,
Experiment,
Survey,
Dashboard,
DashboardTile,
Text,
User,
)
from posthog.warehouse.models import DataWarehouseTable

admin.site.register(FeatureFlag)
admin.site.register(DataWarehouseTable)


Expand Down Expand Up @@ -148,6 +150,98 @@ class GroupTypeMappingInline(admin.TabularInline):
min_num = 5


@admin.register(Cohort)
class CohortAdmin(admin.ModelAdmin):
list_display = (
"id",
"name",
"team_link",
"created_at",
"created_by",
)
list_display_links = ("id", "name")
list_select_related = ("team", "team__organization")
search_fields = ("id", "name", "team__name", "team__organization__name")
autocomplete_fields = ("team", "created_by")
ordering = ("-created_at",)

def team_link(self, cohort: Cohort):
return format_html(
'<a href="/admin/posthog/team/{}/change/">{}</a>',
cohort.team.pk,
cohort.team.name,
)


@admin.register(FeatureFlag)
class FeatureFlagAdmin(admin.ModelAdmin):
list_display = (
"id",
"key",
"team_link",
"created_at",
"created_by",
)
list_display_links = ("id", "key")
list_select_related = ("team", "team__organization")
search_fields = ("id", "key", "team__name", "team__organization__name")
autocomplete_fields = ("team", "created_by")
ordering = ("-created_at",)

def team_link(self, flag: FeatureFlag):
return format_html(
'<a href="/admin/posthog/team/{}/change/">{}</a>',
flag.team.pk,
flag.team.name,
)


@admin.register(Experiment)
class ExperimentAdmin(admin.ModelAdmin):
list_display = (
"id",
"name",
"team_link",
"created_at",
"created_by",
)
list_display_links = ("id", "name")
list_select_related = ("team", "team__organization")
search_fields = ("id", "name", "team__name", "team__organization__name")
autocomplete_fields = ("team", "created_by")
ordering = ("-created_at",)

def team_link(self, experiment: Experiment):
return format_html(
'<a href="/admin/posthog/team/{}/change/">{}</a>',
experiment.team.pk,
experiment.team.name,
)


@admin.register(Survey)
class SurveyAdmin(admin.ModelAdmin):
list_display = (
"id",
"name",
"team_link",
"created_at",
"created_by",
)
list_display_links = ("id", "name")
list_select_related = ("team", "team__organization")
search_fields = ("id", "name", "team__name", "team__organization__name")
autocomplete_fields = ("team", "created_by")
ordering = ("-created_at",)

def team_link(self, experiment: Experiment):
return format_html(
'<a href="/admin/posthog/team/{}/change/">{}</a>',
experiment.team.pk,
experiment.team.name,
)


@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
list_display = (
Expand Down

0 comments on commit 550bb8d

Please sign in to comment.