This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
from django.db import models, transaction | |
class Account(models.Model): | |
balance = models.IntegerField(default=0) | |
user = models.ForeignKey(User) | |
def get_queryset(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
from django.db import models, transaction | |
class Account(models.Model): | |
balance = models.IntegerField(default=0) | |
user = models.ForeignKey(User) | |
def deposit(self, amount): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import generics | |
from django.shortcuts import get_object_or_404 | |
class RecordRetrieveView(generics.RetrieveAPIView): | |
serializer_class = RecordSerializer | |
def get_object(self): | |
return get_object_or_404(Record, id=self.request.query_params['id']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import generics | |
from .models import Record | |
from django.http import Http404 | |
class RecordRetrieveView(generics.RetrieveAPIView): | |
serializer_class = RecordSerializer | |
def get_object(self): | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE "record" | |
SET "name" = 'new record name' | |
WHERE "record"."id" = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> record = Record.objects.get(id=1) | |
>>> record.name = "new record name" | |
>>> record.save(update_fields=['name']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> record = Record.objects.get(id=1) | |
>>> record.name = "new record name" | |
>>> record.save() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UPDATE "record" | |
SET "name" = 'new record name', | |
"created_at" = '2021-06-12T15:09:05.019020+00:00' :: timestamptz, | |
"is_deleted" = FALSE | |
WHERE ""id" = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> record = Record.objects.get(id=1) | |
>>> record.name = "new record name" | |
>>> record.save() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Country(models.Model): | |
name = models.CharField(max_length=255) | |
total_population = models.IntegerField() | |
class Person(models.Model): | |
full_name = models.CharField(max_length=255) | |
first_dose_received_on = models.DateTimeField(null=True, blank=True) | |
second_dose_received_on = models.DateTimeField(null=True, blank=True) |
NewerOlder