Skip to content

Instantly share code, notes, and snippets.

@kingbuzzman
Created May 23, 2023 16:53
Show Gist options
  • Save kingbuzzman/454d70eb433d05005a667e8e46a0182b to your computer and use it in GitHub Desktop.
Save kingbuzzman/454d70eb433d05005a667e8e46a0182b to your computer and use it in GitHub Desktop.
Presentation -- Monday, May 23 -- django
marp theme paginate $size backgroundColor
true
gaia
true
14580

Model instance reference (Create, Refresh, Delete, _state)

Moderator: Javier Buzzi


Create

link

Model.objects.create(property1=value1, property2=value2)
m = Model(property1=value1, property2=value2)
m.save()

  • Whats happening under the hood?
  • Whats happens to the related objects?
  • What happens if the object is already in the database?

Refresh

link

m.refresh_from_db()

code

  • Whats happening under the hood?
  • Whats happens to the related objects?
  • What happens if the object is not in the database?

Delete

link

m.delete()
Model.objects.filter(id=m.id).delete()

code / code

  • Whats happening under the hood?
  • Whats happens to the related objects?
  • What happens if the object is not in the database?

_stage

link

m._state

code

  • Whats happening under the hood?
  • Why is it important?
  • What happens if it's m.pk is None and m._state.adding is False?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment