Django Product Evaluation
This Evaluations is part of the Django Audit and focuses mainly on the Djangos Persistency Layer.
Important Note: This Evaluation contains simplifying constructs that are not part of the original Django Product. Thus you cannot use it a a django quick start.'
Installation
Basics
- $ svn co http://code.djangoproject.com/svn/django/trunk/ django
- $ cd django => /django
- $ setupy.py develop
- Install sqlite3 and python bindings for sqlite3
Schema Evolution Support - from Django Schema Evolution
- within the directory /django
- cd django => /django/django
- $ svn co http://case.lazaridis.com/svn/main/django/rework rework
- copy rework/django-admin.py to django/django/bin/
Further Resources (not needed)
Create a Project
$ django-admin.py startproject eval $ cd eval
Create the Database
within folder "eval"
$ manage.py syncdb
Run the Development Server
$ manage.py runserver
Create an Application
# within folder "eval" $ manage.py startapp cars
# within /eval/settings.py INSTALLED_APPS ... 'eval.cars'
Create a Class: Car
# within /cars/models.py class Car(models.Model): manufacturer = models.CharField(maxlength=30) model = models.CharField(maxlength=30) modelYear = models.IntegerField() def __str__(self): return '%s %s %s' % (self.modelYear, self.manufacturer, self.model) class Admin: pass
Evolve the Database
$ manage.py syncdb
Add Instances
Use the Admin to add instances
Create a Class: Owner
class Owner(models.Model): name = models.CharField(maxlength=50) profession = models.CharField(maxlength=50) def __str__(self): return self.name class Admin: pass
Create a Relation: 1:1
class Car: ... owner = models.ForeignKey('Owner', blank=True, null=True)
Evolve the Database
$ manage.py syncdb
Add Instances and Relations
use the admin to create instances.
Create a Class: Driver
class Driver(models.Model): name = models.CharField(maxlength=50) licenseType = models.CharField(maxlength=30) car = models.ForeignKey(Car) def __str__(self): return self.name class Admin: pass
Create a Relation: 1:N
Within class *Driver*
car = models.ForeignKey(Car)
Evolve the Database
$ manage.py syncdb
Add Instances and Relations
use the admin to create instances.
Define a Class: Road
class Road(models.Model): name = models.CharField(maxlength=50) length = models.IntegerField() def __str__(self): return self.name class Admin: pass
Create a Relation: M:N
class Road(models.Model): ... cars_passed = models.ManyToManyField('Car')
Evolve the Database
$ manage.py syncdb
Add Instances and Relations
use the admin to create instances.
Tasks / Suggestions for Django Team
- Replace command "django-admin.py" by "django-admin" or "django"
- Replace command "manage.py" by "django"
- Enable sqlite3 database / filename by default
- Externalize database settings (e.g. dbdefault.py)
- Enable Admin application by default
- Create a superuser by default (e.g. user:admin / pass:django)
- Rename "startapp" to "createapp"
- Provide basic Database Evolution (e.g. add field)
- Provided temporarily within Django Schema Evolution