Skip to content

Commit

Permalink
fix(surveys): Exclude nullable fields from django admin (#25550)
Browse files Browse the repository at this point in the history
By default, Django admin assumes that all fields are required, even if they're defined as NULL=true, blank=true in the django model specification. This is an issue if we want to change just one property start_date of a Survey, which is a common request.
  • Loading branch information
Phanatic authored Oct 12, 2024
1 parent 9f60b9c commit bc283b4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions posthog/admin/admins/survey_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ class SurveyAdmin(admin.ModelAdmin):
autocomplete_fields = ("team", "created_by")
ordering = ("-created_at",)

def get_form(self, request, obj=None, change=False, **kwargs):
form = super().get_form(request, obj, **kwargs)
for field in [
"start_date",
"end_date",
"responses_limit",
"iteration_count",
"iteration_frequency_days",
"iteration_start_dates",
"current_iteration",
"current_iteration_start_date",
"actions",
]:
form.base_fields[field].required = False
return form

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

0 comments on commit bc283b4

Please sign in to comment.