# Generate 8 random characters.
cat /proc/sys/kernel/random/uuid | cut -c 1-8
>>> class Foo:
... pass
...
>>> class Bar(Foo):
... pass
...
>>> foo = Foo()
>>> bar = Bar()
>>> isinstance(foo, Foo)
True
>>> isinstance(foo, Bar)
False
>>> isinstance(bar, Bar)
True
>>> isinstance(bar, Foo)
True
def forward(apps, schema_editor):
MyModel = apps.get_model('myapp', 'MyModel')
def reverse(apps, schema_editor):
MyModel = apps.get_model('myapp', 'MyModel')
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Command template'
def add_arguments(self, parser):
parser.add_argument('answer', type=int)
def handle(self, *args, **options):
self.stdout.write(self.style.SUCCESS(f"The answer is {options['answer']}"))
YES_NO_CHOICES = (
(None, ""),
(True, "Yes"),
(False, "No"),
)
foo = models.BooleanField(choices=YES_NO_CHOICES, null=True)
# FIXME: Remove debug code.
from django.db import connection
print(connection.queries)
print(len(connection.queries))
def clean(self):
cleaned_data = super().clean()
return cleaned_data
# list tables
\d
# describe table
\d table_name
# or
\d+ table_name
# connect to a database
\c db_name
# or
\connect db_name
# copy to csv
\copy [Table/Query] to '[Relative Path/filename.csv]' csv header
# example
\copy (select name from public.groups) to "groups.csv" csv header
# run file
psql -f [query.sql]
# run file and output to csv
psql --csv -f [query.sql] > [query.csv]
# List all users
\du
# Turn off the pager output
\pset pager off
# Update package-lock.json
npm install --package-lock-only
.inline-list {
display: flex;
> div:not(:empty) + div:not(:empty)::before {
content: ", ";
}
&:has(div:not(:empty))::before {
content: "(";
}
&:has(div:not(:empty))::after {
content: ")";
}
}
<div class="govuk-body inline-list">
<div>foo</div><div>bar</div><div>baz</div>
</div>
<div class="govuk-body inline-list">
<div></div><div>bar</div><div>baz</div>
</div>
<div class="govuk-body inline-list">
<div>foo</div><div></div><div></div>
</div>
<div class="govuk-body inline-list">
<div></div><div></div><div></div>
</div>
https://github.com/uktrade/digital-workspace-v2/pull/292/files