SlideShare a Scribd company logo
1 of 16
Download to read offline
A brief history of
Django model syntax
r1000
January 2004
cms/apps/polls/dblayout.sql
BEGIN;


CREATE TABLE polls (
     id serial PRIMARY KEY,
     label varchar(20) NOT NULL, -- used by the template and possibly by the URL
     release_date timestamp with time zone NOT NULL,
     expire_date timestamp with time zone NOT NULL,
     question varchar(255) NOT NULL
);


CREATE INDEX polls_label ON polls (label);


CREATE TABLE poll_choices (
     id serial PRIMARY KEY,
     polls_id integer REFERENCES polls(id),
     choice varchar(255) NOT NULL,
     votes integer NOT NULL DEFAULT 0
);


CREATE TABLE poll_logged_votes (
     poll_id integer NOT NULL REFERENCES polls(id),
     choice_id integer NOT NULL REFERENCES poll_choices(id),
     ip_address inet NOT NULL,
     vote_time timestamp with time zone NOT NULL,
     PRIMARY KEY (poll_id, ip_address, vote_time)
);


CREATE TABLE polls_sites (
     polls_id integer NOT NULL REFERENCES polls(id),
     sites_id integer NOT NULL REFERENCES sites(id),
     PRIMARY KEY (polls_id, sites_id)
);


COMMIT;
cms/apps/polls/polls.py
class PollDoesNotExist(ObjectDoesNotExist):
    pass


class ChoiceDoesNotExist(ObjectDoesNotExist):
    pass


# ...


class Poll:
    def __init__(self, id, label, release_date, expire_date, question):
        # ...


    def save(self):
        # ...


    def get_choices(self):
        # ...


# ...


def get_poll_by_id(poll_id):
    # ...


def get_poll_by_label(label, year, month):
    # ...


def get_poll_list(year=None, month=None):
    # ...
r4000
August 2004
cms/datadescriptions/polls.py
class Poll(gen.DataDescription):
    app_name = APP_NAME
    app_label = APP_LABEL
    module_name = 'polls'
    object_name = 'Poll'
    object_name_verbose = 'poll'
    db_table = 'polls'
    representation = ['return self.question']
    fields = (
        gen.AutoincrementField('id', 'ID', primary_key=True),
        gen.SlugField('slug', 'slug', unique_for_month='pub_date'),
        gen.CharacterField('question', 'question', maxlength=255),
        gen.DatetimeField('pub_date', 'date published',
            create_list_lookup_function=True, lookup=gen.DATEPART, create_next_previous=True),
        gen.DatetimeField('expire_date', 'expiration date'),
        gen.ManyToManyField('sites', 'sites', can_be_blank=True,
            relationship=gen.ManyToManyRelation(core.Site, 'site_id')),
    )
    list_ordering_tuple = (('pub_date', gen.ORDER_ASCENDING),)
    exceptions = (
        ('AlreadyVoted', None),
        ('PollClosed', None),
        ('InvalidVote', quot;An attempt to vote for a choice that isn't associated with the given pollquot;)
    )
    generate_admin = True
    hierarchical_admin = (gen.BY_DATE, 'pub_date')
    add_permission = ('add_poll', 'Can add polls')
    change_permission = ('change_poll', 'Can change polls')
    template_admin_form = 'polls_form'
    admin_url = 'polls'
    admin_field_conf = (
        (None, {'classes': ('aligned',), 'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites')}),
    )
    extra_model_code_top = quot;from settings import POLL_VOTE_INTERVALquot;
cms/apps/polls/polls.py




# DO NOT EDIT THIS FILE MANUALLY. IT WAS GENERATED BY A PROGRAM.
r8825
         June 2005
First public Django release
ellington/polls/models/polls.py
class Poll(meta.Model):
    db_table = 'polls'
    fields = (
        meta.SlugField('slug', 'slug', unique_for_month='pub_date'),
        meta.CharField('question', 'question', maxlength=255),
        meta.DateTimeField('pub_date', 'date published'),
        meta.DateTimeField('expire_date', 'expiration date'),
        meta.ManyToManyField(core.Site),
        meta.PositiveSmallIntegerField('choice_votes', 'choice votes', default=1,
             help_text=quot;How many choices a person can vote for at once.quot;),
    )
    ordering = ('-pub_date',)
    exceptions = ('AlreadyVoted', 'PollClosed', 'InvalidVote', 'TooFewChoices', 'TooManyChoices')
    get_latest_by = 'pub_date'
    admin = meta.Admin(
        fields = (
             (None, {'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites', 'choice_vo
        ),
        list_display = ('question', 'pub_date', 'expire_date'),
        list_filter = ('sites', 'pub_date'),
        date_hierarchy = 'pub_date',
        search_fields = ('question', 'slug'),
    )
r9000
Django 0.91
ellington/polls/models/polls.py
class Poll(meta.Model):
    slug = meta.SlugField(unique_for_month='pub_date')
    question = meta.CharField(maxlength=255)
    pub_date = meta.DateTimeField('date published')
    expire_date = meta.DateTimeField('expiration date')
    sites = meta.ManyToManyField(core.Site)
    choice_votes = meta.PositiveSmallIntegerField(default=1)
    class META:
        db_table = 'polls'
        ordering = ('-pub_date',)
        exceptions = ('AlreadyVoted', 'PollClosed', 'InvalidVote', 'TooFewChoices', 'TooManyChoic
        get_latest_by = 'pub_date'
        admin = meta.Admin(
            fields = (
                  (None, {'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites')}),
            ),
            list_display = ('question', 'pub_date', 'expire_date'),
            list_filter = ('sites', 'pub_date'),
            date_hierarchy = 'pub_date',
            search_fields = ('question', 'slug'),
        )
r17000+
 Trunk(ish)
ellington/polls/models.py

class Poll(models.Model):
    slug = models.SlugField(unique_for_month='pub_date')
    question = models.CharField(maxlength=255)
    pub_date = models.DateTimeField('date published')
    expire_date = models.DateTimeField('expiration date')
    sites = models.ManyToManyField(core.Site)
    choice_votes = models.PositiveSmallIntegerField(default=1)


    class Meta:
        ordering = ('-pub_date',)
        get_latest_by = 'pub_date'


    class Admin:
        list_display = ('question', 'pub_date', 'expire_date')
        list_filter = ('sites', 'pub_date')
        date_hierarchy = 'pub_date'
        search_fields = ('question', 'slug')
        save_as = True
newforms-admin
ellington/polls/admin.py




from ellington.polls.models import Poll


class PollOptions:
    list_display = ('question', 'pub_date', 'expire_date')
    list_filter = ('sites', 'pub_date')
    date_hierarchy = 'pub_date'
    search_fields = ('question', 'slug')
    save_as = True


admin.site.register(Poll, PollOptions)
Want to hack on
  Ellington?
   jacob@jacobian.org

More Related Content

Viewers also liked

Cadr plus emailer
Cadr plus emailerCadr plus emailer
Cadr plus emailer4dutchie
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Djangojeff_croft
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To DjangoJay Graves
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC FrameworkBala Kumar
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 

Viewers also liked (6)

Cadr plus emailer
Cadr plus emailerCadr plus emailer
Cadr plus emailer
 
Getting Started With Django
Getting Started With DjangoGetting Started With Django
Getting Started With Django
 
Django introduction
Django introductionDjango introduction
Django introduction
 
Introduction To Django
Introduction To DjangoIntroduction To Django
Introduction To Django
 
Django - Python MVC Framework
Django - Python MVC FrameworkDjango - Python MVC Framework
Django - Python MVC Framework
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 

Similar to A brief history of Django model syntax

Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with DjangoSimon Willison
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYCMike Dirolf
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용KyeongMook "Kay" Cha
 
Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8pedroburonv
 
Creating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfCreating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfShaiAlmog1
 
Salesforce Data Models for Pros: Simplifying The Complexities
Salesforce Data Models for Pros: Simplifying The ComplexitiesSalesforce Data Models for Pros: Simplifying The Complexities
Salesforce Data Models for Pros: Simplifying The ComplexitiesSalesforce Developers
 
Digital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate ModuleDigital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate ModuleErich Beyrent
 
SFDC Data Models For Pros - Simplifying The Complexities
SFDC Data Models For Pros - Simplifying The ComplexitiesSFDC Data Models For Pros - Simplifying The Complexities
SFDC Data Models For Pros - Simplifying The ComplexitiesBaruch Oxman
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryPamela Fox
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Djangocolinkingswood
 
Web осень 2012 лекция 7
Web осень 2012 лекция 7Web осень 2012 лекция 7
Web осень 2012 лекция 7Technopark
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimMir Nazim
 
Web весна 2013 лекция 7
Web весна 2013 лекция 7Web весна 2013 лекция 7
Web весна 2013 лекция 7Technopark
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksShawn Rider
 
YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기Jinho Jung
 
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeDjango in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeHarvard Web Working Group
 

Similar to A brief history of Django model syntax (20)

Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
Django Search
Django SearchDjango Search
Django Search
 
Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8Lo nuevo de Django 1.7 y 1.8
Lo nuevo de Django 1.7 y 1.8
 
Creating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfCreating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdf
 
Salesforce Data Models for Pros: Simplifying The Complexities
Salesforce Data Models for Pros: Simplifying The ComplexitiesSalesforce Data Models for Pros: Simplifying The Complexities
Salesforce Data Models for Pros: Simplifying The Complexities
 
Digital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate ModuleDigital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate Module
 
SFDC Data Models For Pros - Simplifying The Complexities
SFDC Data Models For Pros - Simplifying The ComplexitiesSFDC Data Models For Pros - Simplifying The Complexities
SFDC Data Models For Pros - Simplifying The Complexities
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Web осень 2012 лекция 7
Web осень 2012 лекция 7Web осень 2012 лекция 7
Web осень 2012 лекция 7
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir NazimDjango Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
 
Web весна 2013 лекция 7
Web весна 2013 лекция 7Web весна 2013 лекция 7
Web весна 2013 лекция 7
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
 
YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기YDN KR Tech Talk : Pipes 와 YQL 활용하기
YDN KR Tech Talk : Pipes 와 YQL 활용하기
 
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeDjango in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
 

More from Jacob Kaplan-Moss

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011Jacob Kaplan-Moss
 
Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009Jacob Kaplan-Moss
 
Building a web framework: Django's design decisions
Building a web framework: Django's design decisionsBuilding a web framework: Django's design decisions
Building a web framework: Django's design decisionsJacob Kaplan-Moss
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five yearsJacob Kaplan-Moss
 

More from Jacob Kaplan-Moss (12)

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009
 
Snakes on the Web
Snakes on the WebSnakes on the Web
Snakes on the Web
 
Django In The Real World
Django In The Real WorldDjango In The Real World
Django In The Real World
 
Building a web framework: Django's design decisions
Building a web framework: Django's design decisionsBuilding a web framework: Django's design decisions
Building a web framework: Django's design decisions
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
State Of Django
State Of DjangoState Of Django
State Of Django
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five years
 
Django Update (OSCON 2007)
Django Update (OSCON 2007)Django Update (OSCON 2007)
Django Update (OSCON 2007)
 

Recently uploaded

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?Mark Billinghurst
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGDSC PJATK
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...FIDO Alliance
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 

Recently uploaded (20)

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 

A brief history of Django model syntax

  • 1. A brief history of Django model syntax
  • 3. cms/apps/polls/dblayout.sql BEGIN; CREATE TABLE polls ( id serial PRIMARY KEY, label varchar(20) NOT NULL, -- used by the template and possibly by the URL release_date timestamp with time zone NOT NULL, expire_date timestamp with time zone NOT NULL, question varchar(255) NOT NULL ); CREATE INDEX polls_label ON polls (label); CREATE TABLE poll_choices ( id serial PRIMARY KEY, polls_id integer REFERENCES polls(id), choice varchar(255) NOT NULL, votes integer NOT NULL DEFAULT 0 ); CREATE TABLE poll_logged_votes ( poll_id integer NOT NULL REFERENCES polls(id), choice_id integer NOT NULL REFERENCES poll_choices(id), ip_address inet NOT NULL, vote_time timestamp with time zone NOT NULL, PRIMARY KEY (poll_id, ip_address, vote_time) ); CREATE TABLE polls_sites ( polls_id integer NOT NULL REFERENCES polls(id), sites_id integer NOT NULL REFERENCES sites(id), PRIMARY KEY (polls_id, sites_id) ); COMMIT;
  • 4. cms/apps/polls/polls.py class PollDoesNotExist(ObjectDoesNotExist): pass class ChoiceDoesNotExist(ObjectDoesNotExist): pass # ... class Poll: def __init__(self, id, label, release_date, expire_date, question): # ... def save(self): # ... def get_choices(self): # ... # ... def get_poll_by_id(poll_id): # ... def get_poll_by_label(label, year, month): # ... def get_poll_list(year=None, month=None): # ...
  • 6. cms/datadescriptions/polls.py class Poll(gen.DataDescription): app_name = APP_NAME app_label = APP_LABEL module_name = 'polls' object_name = 'Poll' object_name_verbose = 'poll' db_table = 'polls' representation = ['return self.question'] fields = ( gen.AutoincrementField('id', 'ID', primary_key=True), gen.SlugField('slug', 'slug', unique_for_month='pub_date'), gen.CharacterField('question', 'question', maxlength=255), gen.DatetimeField('pub_date', 'date published', create_list_lookup_function=True, lookup=gen.DATEPART, create_next_previous=True), gen.DatetimeField('expire_date', 'expiration date'), gen.ManyToManyField('sites', 'sites', can_be_blank=True, relationship=gen.ManyToManyRelation(core.Site, 'site_id')), ) list_ordering_tuple = (('pub_date', gen.ORDER_ASCENDING),) exceptions = ( ('AlreadyVoted', None), ('PollClosed', None), ('InvalidVote', quot;An attempt to vote for a choice that isn't associated with the given pollquot;) ) generate_admin = True hierarchical_admin = (gen.BY_DATE, 'pub_date') add_permission = ('add_poll', 'Can add polls') change_permission = ('change_poll', 'Can change polls') template_admin_form = 'polls_form' admin_url = 'polls' admin_field_conf = ( (None, {'classes': ('aligned',), 'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites')}), ) extra_model_code_top = quot;from settings import POLL_VOTE_INTERVALquot;
  • 7. cms/apps/polls/polls.py # DO NOT EDIT THIS FILE MANUALLY. IT WAS GENERATED BY A PROGRAM.
  • 8. r8825 June 2005 First public Django release
  • 9. ellington/polls/models/polls.py class Poll(meta.Model): db_table = 'polls' fields = ( meta.SlugField('slug', 'slug', unique_for_month='pub_date'), meta.CharField('question', 'question', maxlength=255), meta.DateTimeField('pub_date', 'date published'), meta.DateTimeField('expire_date', 'expiration date'), meta.ManyToManyField(core.Site), meta.PositiveSmallIntegerField('choice_votes', 'choice votes', default=1, help_text=quot;How many choices a person can vote for at once.quot;), ) ordering = ('-pub_date',) exceptions = ('AlreadyVoted', 'PollClosed', 'InvalidVote', 'TooFewChoices', 'TooManyChoices') get_latest_by = 'pub_date' admin = meta.Admin( fields = ( (None, {'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites', 'choice_vo ), list_display = ('question', 'pub_date', 'expire_date'), list_filter = ('sites', 'pub_date'), date_hierarchy = 'pub_date', search_fields = ('question', 'slug'), )
  • 11. ellington/polls/models/polls.py class Poll(meta.Model): slug = meta.SlugField(unique_for_month='pub_date') question = meta.CharField(maxlength=255) pub_date = meta.DateTimeField('date published') expire_date = meta.DateTimeField('expiration date') sites = meta.ManyToManyField(core.Site) choice_votes = meta.PositiveSmallIntegerField(default=1) class META: db_table = 'polls' ordering = ('-pub_date',) exceptions = ('AlreadyVoted', 'PollClosed', 'InvalidVote', 'TooFewChoices', 'TooManyChoic get_latest_by = 'pub_date' admin = meta.Admin( fields = ( (None, {'fields': ('question', 'slug', 'pub_date', 'expire_date', 'sites')}), ), list_display = ('question', 'pub_date', 'expire_date'), list_filter = ('sites', 'pub_date'), date_hierarchy = 'pub_date', search_fields = ('question', 'slug'), )
  • 13. ellington/polls/models.py class Poll(models.Model): slug = models.SlugField(unique_for_month='pub_date') question = models.CharField(maxlength=255) pub_date = models.DateTimeField('date published') expire_date = models.DateTimeField('expiration date') sites = models.ManyToManyField(core.Site) choice_votes = models.PositiveSmallIntegerField(default=1) class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' class Admin: list_display = ('question', 'pub_date', 'expire_date') list_filter = ('sites', 'pub_date') date_hierarchy = 'pub_date' search_fields = ('question', 'slug') save_as = True
  • 15. ellington/polls/admin.py from ellington.polls.models import Poll class PollOptions: list_display = ('question', 'pub_date', 'expire_date') list_filter = ('sites', 'pub_date') date_hierarchy = 'pub_date' search_fields = ('question', 'slug') save_as = True admin.site.register(Poll, PollOptions)
  • 16. Want to hack on Ellington? jacob@jacobian.org