advertisement

A brief history of Django model syntax

50 %
50 %
advertisement
Information about A brief history of Django model syntax

Published on December 3, 2007

Author: jacobian

Source: slideshare.net

advertisement

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

Add a comment

Related pages

A brief history of Django model syntax - PdfSR.com

A brief history of Django model syntax . Home; Upload; Search; Marketplace; FAQ; ... A brief history of Django model syntaxr1000January 2004cms/apps/polls ...
Read more

Chapter 5: Models - Django Book

Chapter 5: Models. In Chapter 3, we ... in a nice and compact syntax. ... A Django model describes more than the database table layout for an object; ...
Read more

Model Field Reference Django Documentation Django - Documents

Share Model Field Reference Django Documentation Django. ... A brief history of Django model syntax Django 1.1 Documentation, Aug 1 2009 Comments.
Read more

Django Model Report - Documents

A brief history of Django model syntax. django. Django. Django. Django. Django. Django. django. django. Django. Login or Join. Processing Login successful ...
Read more

pyvideo.org: Videos of DjangoCon 2011

... Videos of DjangoCon 2011. ... Django can be a model citizen among ... and what do designers do? - A brief trip down memory lane, and how Django came to ...
Read more

Custom Query – Django

... for an object would also show the history of its super-object(s) (if your model uses ... brief discussion on django ... different syntax), ...
Read more

URL dispatcher | Django documentation | Django

... the syntax for named regular ... /history/$', views. history), url (r'^(?P ... In higher level code related to handling of URLs of Django model ...
Read more

pyvideo.org - Lightning Talks - Wednesday morning

Lightning Talks - Wednesday morning. 00:00 - Steve Ivy: Pushcode; 05:00 - Jacob Kaplan-Moss: Brief history of Django model syntax ; 14:20 - Gabriel Grant ...
Read more

DjangoResources – Django

Django resources. This page lists open ... so use search content using django model filtering expressions. ... A brief reason for removal from this list is ...
Read more