Changes between Initial Version and Version 1 of CookBookSplitModelsToFiles


Ignore:
Timestamp:
May 4, 2006, 2:15:37 AM (18 years ago)
Author:
Antti Kaihola
Comment:

Created.

Legend:

Unmodified
Added
Removed
Modified
  • CookBookSplitModelsToFiles

    v1 v1  
     1= CookBook - [wiki:CookBookDataModels Data Models] - Splitting models across multiple files =
     2
     3To split models across multiple files, you can do the following (works at least with revision 2819):
     4
     5{{{apps/polls/models/__init__.py}}}:
     6{{{
     7from poll import Poll
     8from choice import Choice
     9}}}
     10
     11{{{apps/polls/models/poll.py}}}:
     12{{{
     13from django.db import models
     14
     15class Poll(models.Model):
     16    question = models.CharField(maxlength=200)
     17    pub_date = models.DateTimeField('date published')
     18
     19    class Meta:
     20        app_label = 'polls'
     21}}}
     22
     23{{{apps/polls/models/choice.py}}}:
     24{{{
     25from django.db import models
     26from poll import Poll
     27
     28class Choice(models.Model):
     29    poll = models.ForeignKey(Poll)
     30    choice = models.CharField(maxlength=200)
     31    votes = models.IntegerField()
     32
     33    class Meta:
     34        app_label = 'polls'
     35}}}
     36
     37Ok so the example is a bit stupid but it should illustrate the point.
Back to Top