Skip to content

Instantly share code, notes, and snippets.

View nezort11's full-sized avatar

George Zorin nezort11

View GitHub Profile
@nezort11
nezort11 / django-project-patterns.md
Created September 14, 2021 15:21
Django Project Patterns

Django Project Patterns

Project development:

  1. Describe
  2. Design
  3. Implement

What should be done for every Django/SPA project?

@nezort11
nezort11 / django-form-fields.md
Created September 13, 2021 21:05
Django Form Fields

Form and fields

form.fields: (BoundField) 1. form.visible_fields (BoundField) - not field.is_hidden 2. form.hidden_fields (BoundField) - field.is_hidden

form.iter = form.fields form.field_name = FloatField (UnBoundField)

@nezort11
nezort11 / django-orm-relations.md
Created September 13, 2021 21:04
Django ORM relations

Django ORM relations

  • Directional
  • Idirectional = Bidirectional
  • Unidirectional

Relations

  • ManyToOne (M:1) - PK/FK relation
  • OneToMany (1:M) - no SQL (reversed M:1)
@nezort11
nezort11 / django-validation.md
Created September 13, 2021 21:00
Djnago validation

Django validation

Important note: direct model instance manager.create()/save() doesn't validate (run instance.full_clean()). Only form validate instance (calls instance.full_clean()).

ModelForm validation process (Form + Model instance):

  1. form.is_valid()
  2. form.errors()
  3. form.full_clean() - populate errors and cleanded_data