agentleFS
kjnezkjnez/claude-code-django/.claude/skills/django-forms/SKILL.md

django-forms

Skill177 starsChanged 10 months agoMITView on GitHub

Django form handling patterns including ModelForm, validation, clean methods, and HTMX form submission. Use when building forms, implementing validation, or handling form submission.

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 6 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Prefer ModelForm for model-backed forms

    line 10
  2. Distinctive:

    Keep validation logic in forms, not views

    line 11
  3. Distinctive:

    Always handle and display form errors

    line 12
  4. Very specific:

    Use commit=False when you need to modify the instance before saving

    line 13
  5. Distinctive:

    Use for: format checks, uniqueness, normalization

    line 20
  6. Very specific:

    Use self.add_error(field, message) for field-specific errors

    line 25
  7. Distinctive:

    Use for: password confirmation, conditional requirements

    line 26
  8. Very specific:

    Use form.save(commit=False) to set additional fields (e.g., author)

    line 32
  9. Very specific:

    Check request.headers.get("HX-Request") for HTMX requests

    line 36
  10. Very specific:

    Use HX-Trigger header to notify other components

    line 38
  11. Very specific:

    Use partial templates (_form.html) for HTMX responses

    line 44
  12. Very specific:

    Use inlineformset_factory for related model collections

    line 55
  13. Distinctive:

    Not displaying form errors to users

    line 64

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Django Forms

Philosophy

  • Prefer ModelForm for model-backed forms
  • Keep validation logic in forms, not views
  • Always handle and display form errors
  • Use commit=False when you need to modify the instance before saving

Validation

Field-level (clean_<field>):

  • Validate and transform a single field
  • Return the cleaned value or raise ValidationError
  • Use for: format checks, uniqueness, normalization

Cross-field (clean):

  • Call super().clean() first
  • Access multiple fields via cleaned_data
  • Use self.add_error(field, message) for field-specific errors
  • Use for: password confirmation, conditional requirements

View Integration

  • Check request.method explicitly
  • Instantiate form with request.POST for POST, empty for GET
  • Use form.save(commit=False) to set additional fields (e.g., author)
  • Return redirect on success, re-render with form on error

HTMX handling:

  • Check request.headers.get("HX-Request") for HTMX requests
  • Return partial template on success/error for HTMX
  • Use HX-Trigger header to notify other components

Templates

  • Display form.non_field_errors for cross-field errors
  • Display field.errors for each field
  • Use partial templates (_form.html) for HTMX responses
  • Include loading indicator with hx-indicator

Widgets

  • Override in Meta.widgets dict
  • Set HTML attributes via attrs parameter
  • Common: Textarea(attrs={"rows": 5}), DateTimeInput(attrs={"type": "datetime-local"})

Formsets

  • Use inlineformset_factory for related model collections
  • Validate both form and formset: form.is_valid() and formset.is_valid()
  • Pass instance for editing existing parent objects

Pitfalls

  • Validating in views instead of forms
  • Silently redirecting without checking is_valid()
  • Forgetting commit=False when setting related fields
  • Not displaying form errors to users

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.