• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Python Metaclass and How Django uses them: Foss 2010
 

Python Metaclass and How Django uses them: Foss 2010

on

  • 570 views

 

Statistics

Views

Total Views
570
Views on SlideShare
570
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Python Metaclass and How Django uses them: Foss 2010 Python Metaclass and How Django uses them: Foss 2010 Presentation Transcript

    • Python Meta classes and howDjango uses them Lakshman Prasad
    • Meta Classes A Design pattern Dynamically create classes Enables Flexibility, Good API Used by Frameworks Perform “Magic”
    • Where Meta Classes? Frameworks, frameworks, frameworks. Django uses them extensively. Scrappy, a web scrapping framework. Flexible Django apps. Eg: Django-registration
    • Executes the code when encounteredCreates namespace and stores all variables in it
    • `type` is an inbuilt MetaClassDynamic class = Static classes
    • `__metaclass__` defines metaclases
    • Meta Class MagicDefine a class extending objectExamined type is string, Magic!Enables Declarative Syntax
    • MetaClasses, not always Simple function decorators Unintuitive to end developers, unless explained Python 2.6+ has Class Decorators But being powerful, where they are needed, indespesible
    • Django Models
    • Django Models Creation Declarative Syntax, No `__metaclass__` New model created in place Options into `Options` object Register in registry called `AppCache` Add attributes to new model
    • Inside Django Models Return the same registered Model from AppCache Original options and Meta options stored in `_meta` Add more useful attributes/classes like `DoesnotExist`, `module_name` and `class_name`
    • Django Forms
    •  Rendering in html Validation for right data Displaying errors Customization options Provided model, storing to the database
    • Dynamic Django forms - 1Forms API is flexible, but often needs Meta Classes`base_fields` and `fields` list store all fieldsChange field attributes while initialization
    • Dynamic Django Forms - 2When high complexity, instantiate a form,dynamically
    • ResourcesPython, Django Documentation, Source.Pro Django, by Marty AlchinDjango-registration v0.7 by James Bennett
    • Thank You!lakshman@uswaretech.com : Build Cutting Edge Web Apps.Small Team of expert Django Developers.Exclusively develop in Django, Python stack.@becomingGuru, @uswaretech