6. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
7. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
name = models.CharField(max_length=50)
8. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
name = models.CharField(max_length=50)
phone = models.CharField(max_length=20, null=True, blank=True)
9. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
name = models.CharField(max_length=50)
phone = models.CharField(max_length=20, null=True, blank=True)
STATUS_PAID = 'paid'
STATUS_TRIALING = 'trialing'
10. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
name = models.CharField(max_length=50)
phone = models.CharField(max_length=20, null=True, blank=True)
STATUS_PAID = 'paid'
STATUS_TRIALING = 'trialing'
STATUS_CHOICES = (
(STATUS_PAID, 'Paid'),
(STATUS_TRIALING, 'Trialing'),
)
11. from django.db import models
class User(models.Model):
email = models.EmailField(
max_length=254, unique=True, help_text='Used as the username')
name = models.CharField(max_length=50)
phone = models.CharField(max_length=20, null=True, blank=True)
STATUS_PAID = 'paid'
STATUS_TRIALING = 'trialing'
STATUS_CHOICES = (
(STATUS_PAID, 'Paid'),
(STATUS_TRIALING, 'Trialing'),
)
status = models.CharField(
max_length=20, unique=True, choices=STATUS_CHOICES)
14. $ ./manage.py dbshell
psql (9.4.1)
Type "help" for help.
vida=> d accounts_user
Table "public.accounts_user"
Column | Type | Modifiers
--------+------------------------+----------------------
id | integer | not null default ...
email | character varying(254) | not null
name | character varying(50) | not null
phone | character varying(20) |
status | character varying(20) | not null
18. $ ./manage.py dbshell
psql (9.4.1)
Type "help" for help.
vida=> d messaging_message
Table "public.messaging_message"
Column | Type | Modifiers
-----------+---------+----------------------
id | integer | not null default ...
sender_id | integer | not null
61. users = Users.objects.filter(...)
for user in users:
for tm in user.tracked_metrics.all():
print tm.metric.key
Assume 10 users and16 distinct metrics
62. users = Users.objects.filter(...)
for user in users:
for tm in user.tracked_metrics.all():
print tm.metric.key
1 - users
10 - tracked metrics
16 - metrics