| | | |
| this could also be used for editing urls & co .. a | | this could also be used for editing urls & co .. a |
| nd .. you could use named URLs to link to URLs not | | nd .. you could use named URLs to link to URLs not |
| associated with models.. | | associated with models.. |
| | | |
| # Various Comments | | # Various Comments |
| | | |
n | | n | One of the more annoying things when getting start |
| | | ed with django is it's template engine (you can of |
| | | course use another template engine with django..) |
| | | . The reason for this is django's extreme position |
| | | on forcing the developer / designer to move all a |
| | | nd any logic out of templates - This is not necess |
| | | ary good .. or bad .. but requires at least some a |
| | | djustments if you come from more "powerful" templa |
| | | te engines (django template engine is still very p |
| | | owerful - for example the inheritance schema is ve |
| | | ry useful and allows to create great extend able a |
| | | nd customizable applications.).
|
| | |
|
| | | There is quite some opposition against putting all |
| | | logic out of the templates (and hence making more |
| | | developer work necessary, as i understand it) - f |
| | | or example <http://www.cmlenz.net/archives/2007/06 |
| | | /logic-in-templates>
|
| | |
|
| | | (I personally have not much problems with this app |
| | | roach.. especially after seeing quite some busines |
| | | s logic implemented in velocity & co ;) )
|
| | |
|
| # Code Examples | | # Code Examples |
| | | |
n | | n | Well .. there is not all that much code
|
| | |
|
| | | - [All views](http://yourhell.com/svn/sphene/frame |
| | | workcomparison/django/barsite/barcrud/views.py)
|
| | | - [All models](http://yourhell.com/svn/sphene/fram |
| | | eworkcomparison/django/barsite/barcrud/models.py)
|
| | | - [and of course a handful of templates](http://yo |
| | | urhell.com/svn/sphene/frameworkcomparison/django/b |
| | | arsite/barcrud/templates/barcrud/)
|
| | |
|
| | |
|
| | | ## Forms
|
| | |
|
| | | One especially noteworthy feature of django is it' |
| | | s 'forms' classes ('newforms' actually) which allo |
| | | ws an object oriented approach to create forms..
|
| | |
|
| | | It also allows you to automatically generate forms |
| | | out of existing models..
|
| | |
|
| | | For example take a look at the form to create/edit |
| | | bars (for simplicity i've done it in 'models.py' |
| | | usually you probably want to put it all in it's ow |
| | | n python module):
|
| | |
|
| | | class BarForm(forms.ModelForm):
|
| | | beers = forms.MultipleChoiceField( choices |
| | | = BeerChoices(),
|
| | | require |
| | | d = False, )
|
| | |
|
| | | class Meta:
|
| | | model = Bar
|
| | | exclude = ('creationdate', 'editdate', |
| | | 'lasteditor')
|
| | |
|
| | | the template would then simply output the form lik |
| | | e: {{ form }}
|
| | |
|
| | |
|
| | | as you can see - because of the object oriented ap |
| | | proach you could add custom behavior - like error |
| | | checking, additional fields/widgets, etc. it is ve |
| | | ry handy and makes form based applications as easy |
| | | as it gets.
|
| | |
|
| # Conclusion | | # Conclusion |
t | | t |
|