Skip to content

Instantly share code, notes, and snippets.

In [23]: for p in Product.objects.all(): | In [24]: for p in Product.objects.all():
...: print() ...: print()
...: print(p.name) ...: print(p.name)
...: for pv in p.productversion_set.all(): ...: for pv in p.productversion_set.all():
...: print(' Version') ...: print(' Version')
...: for qc in pv.questioncollection_set.all(): ...: for qc in pv.questioncollection_set.all():
...: print(' QC #', qc.position) ...: print(' QC #', qc.position)
...: for q in qc.questions.all(): ...: for q in qc.questions.all():
...: print(' Q #', q.question_code, ...: print(' Q #', q.question_code,
...:
from django.apps import apps
from django.test import TestCase
from django.db.migrations.executor import MigrationExecutor
from django.db import connection
from django.db.models import F
from model_mommy import mommy
class TestMigrations(TestCase):
@pmg103
pmg103 / WithItem.js
Created December 19, 2018 21:00
Use render props to isolate loading/collection from component
const ActivityEdit = ({activity, updateActivity, response}) => (
<div>
<h1>Welcome to {activity.get('name')}</h1>
<button
onClick={() => updateActivity(Map({name: 'New name'}))}
disabled={isPending(response)}
>
Update name
</button>
</div>
@pmg103
pmg103 / serializer_spec.py
Created July 19, 2018 12:26
Have a single source of truth used to specify both fetching and serializing of data
class OrganisationDetail(SerializationSpecMixin, generics.RetrieveAPIView):
queryset = Organisation.objects.all()
serialization_spec = [
'id',
'name',
{'created_by_user': [
'email',
'status',