Changes between Version 1 and Version 2 of MagicRemovalCheatSheet


Ignore:
Timestamp:
May 11, 2006, 9:57:57 PM (19 years ago)
Author:
eugene@…
Comment:

added models

Legend:

Unmodified
Added
Removed
Modified
  • MagicRemovalCheatSheet

    v1 v2  
     1= Removing the magic: the cheat sheet =
     2
    13''Work in progress.''
     4
     5This document assumes a basic familiarity with [wiki:RemovingTheMagic Removing the magic] changes. It is designed to be used as a simple cheat sheet during a conversion process providing links to relevant parts [wiki:RemovingTheMagic Removing the magic] document. It is organized by functional areas: databases, settings, models, views, templates, and template tags. This document doesn't cover new functionality.
     6
     7== Pre-conversion ==
     8
     9''Optional (saves time):'' if your project doesn't have {{{manage.py}}} file in the project's directory, copy it from {{{django/conf/project_template/}}}.
     10
     11== Databases ==
     12
     13Database changes are covered extensively in [wiki:RemovingTheMagic#Databasechangesyoullneedtomake Database changes you'll need to make]. Just execute appropriate SQL scripts.
     14
     15''Optional (saves space):'' {{{package}}} column of {{{auth_permission}}} table is not used anymore. You can drop it by executing following SQL statement (works for MySQL):
     16
     17{{{
     18ALTER TABLE `auth_permission` DROP COLUMN `package`;
     19}}}
     20
     21
     22__Eugene's note__: after conversion I found that my permissions are screwed up. I regenerated them this way:
     23
     24 * Delete a content of following tables (you can do it now):
     25   * {{{auth_group_permissions}}}
     26   * {{{auth_permissions}}}
     27   * {{{auth_user_user_permissions}}}
     28   * {{{django_content_type}}}
     29 * '''After you finished with code changes''', run {{{django-admin.py syncdb}}} or {{{manage.py syncdb}}}. '''Don't do it now!'''
     30
     31It repopulates the content of said tables properly, but an administrator has to reassign group and user permissions again in Admin. Obviously it can be a problem, if you have hundreds of users with arcane permissions.
     32
     33== Models ==
     34
     35 1. If your applications still live in {{{yourproject/apps/}}} directory, you can move them up one level: move {{{yourproject/apps/yourapp/}}} to {{{yourproject/yourapp}}}.
     36 1. [wiki:RemovingTheMagic#Modellocationchanged Relocate models] by moving content of files in your {{{yourapp/models/}}} directory to {{{yourapp/models.py}}} file.
     37 1. If your models use {{{datetime}}} or {{{db}}} modules without exporting them directly, [wiki:RemovingTheMagic#Modelmethodsnolongerautomaticallyhaveaccesstodatetimeanddbmodules add import statements].
     38 1. [wiki:RemovingTheMagic#ModelclassandFieldclassesrenamed/relocated Relocate Model and Field classes]: use {{{django.db.models}}} instead of {{{django.core.meta}}}.
     39 1. [wiki:RemovingTheMagic#MovedadminoptionstoclassAdmin Convert the META.admin member] to new inner {{{class Admin}}} of the model. Don't forget to remove all pesky commas at the end of lines.
     40 1. [wiki:RemovingTheMagic#Changestomodelsyntax Remove from META] following parameters: {{{admin}}} (see the previous step), {{{module_name}}}, {{{exceptions}}}, {{{module_constants}}}, and {{{where_constraints}}}. If now your {{{class META}}} is empty, delete it. Otherwise rename it to {{{class Meta}}}.
     41 1. [wiki:RemovingTheMagic#a__repr__modelmethodisreplacedby__str__ Replace __repr__ with __str__].
     42 1. If you use {{{_pre_save()}}}, {{{_post_save()}}}, {{{_pre_delete()}}}, and/or {{{_post_delete()}}} hooks, [wiki:RemovingTheMagic#Addedamorepowerfulwayofoverridingmodelmethodsremovedhardcoded_pre_save_post_saveetc. replace them] by overriding {{{save()}}} and {{{delete()}}} methods.
     43
     44== Views ==
     45== Templates ==
     46== Template tags ==
     47== Settings ==
     48
     49== Post-conversion ==
     50
     51If you decided to regenerate permissions, now is the good time to execute {{{django-admin.py syncdb}}} or {{{manage.py syncdb}}}. Remember that an administrator should reassign permissions to all users using Admin.
Back to Top