{% extends "base.html" %} {% load static %} {% block title %}{% if object %}Edit Metric{% else %}Create Metric{% endif %} - Analytics{% endblock %} {% block css %} {% endblock %} {% block content %}

{% if object %}Edit Metric{% else %}Create New Metric{% endif %} {% if object %}{{ object.name }}{% else %}Analytics Metric{% endif %}

{% csrf_token %}

Basic Information

{{ form.name }} {% if form.name.errors %}
{{ form.name.errors.0 }}
{% endif %}
{{ form.status }} {% if form.status.errors %}
{{ form.status.errors.0 }}
{% endif %}
{{ form.description }} {% if form.description.errors %}
{{ form.description.errors.0 }}
{% endif %}
{{ form.category }} {% if form.category.errors %}
{{ form.category.errors.0 }}
{% endif %}
{{ form.update_frequency }} {% if form.update_frequency.errors %}
{{ form.update_frequency.errors.0 }}
{% endif %}
{{ form.unit }} {% if form.unit.errors %}
{{ form.unit.errors.0 }}
{% endif %}
e.g., %, $, patients, hours
{{ form.data_type }} {% if form.data_type.errors %}
{{ form.data_type.errors.0 }}
{% endif %}

Target Configuration

{{ form.target_value }} {% if form.target_value.errors %}
{{ form.target_value.errors.0 }}
{% endif %}
Optional target value for this metric
{{ form.target_direction }} {% if form.target_direction.errors %}
{{ form.target_direction.errors.0 }}
{% endif %}
Whether higher or lower values are better
{{ form.warning_threshold }} {% if form.warning_threshold.errors %}
{{ form.warning_threshold.errors.0 }}
{% endif %}
Value that triggers a warning alert
{{ form.critical_threshold }} {% if form.critical_threshold.errors %}
{{ form.critical_threshold.errors.0 }}
{% endif %}
Value that triggers a critical alert

Calculation Configuration

{% if form.sql_query.errors %}
{{ form.sql_query.errors.0 }}
{% endif %}
SQL query that calculates the metric value. Must return a single numeric value.

Advanced Configuration

{{ form.decimal_places }} {% if form.decimal_places.errors %}
{{ form.decimal_places.errors.0 }}
{% endif %}
Number of decimal places to display
{{ form.chart_type }} {% if form.chart_type.errors %}
{{ form.chart_type.errors.0 }}
{% endif %}
{{ form.is_cumulative }}
Values accumulate over time
{{ form.show_on_dashboard }}
Display this metric on the main dashboard
{{ form.tags }} {% if form.tags.errors %}
{{ form.tags.errors.0 }}
{% endif %}
Comma-separated tags for categorization

Form Actions

{% if object %} {% else %} {% endif %} Cancel {% if object %}
Delete Metric {% endif %}

Quick Templates

{% if object %}

Current Status

Current Value: {% if object.current_value is not None %} {{ object.current_value }}{% if object.unit %} {{ object.unit }}{% endif %} {% else %} No data {% endif %}
Last Updated: {{ object.last_updated|date:"M d, Y H:i"|default:"Never" }}
Update Count: {{ object.update_count }}
Status: {{ object.get_status_display }}
{% endif %}

Help & Tips

SQL Query Tips:
  • Query must return a single numeric value
  • Use aggregate functions like COUNT, SUM, AVG
  • Include appropriate WHERE clauses for filtering
  • Test your query before saving
Target Configuration:
  • Set realistic and achievable targets
  • Use warning/critical thresholds for alerts
  • Consider seasonal variations
Update Frequency:
  • Real-time: Updates continuously
  • Hourly: Updates every hour
  • Daily: Updates once per day
  • Weekly: Updates weekly
  • Monthly: Updates monthly
{% endblock %} {% block js %} {% endblock %}