Ticket #2982: model-api.diff

File model-api.diff, 995 bytes (added by Marc Fargas <telenieko@…>, 18 years ago)

Documentation for #2982

  • docs/model-api.txt

     
    17991799        # ...
    18001800        zip_code = models.ForeignKey(ZipCode)
    18011801
     1802Models inside models/
     1803=====================
     1804
     1805As long as your models get larger you, maybe, will want to split them by taking
     1806them out of models.py and placing every model on a separate file in models/ .
     1807First create the directory models/ inside your application, and create a file
     1808called __init__.py inside it importing your models, i.e.:
     1809
     1810   from poll import Poll
     1811   from choice import Choice
     1812
     1813That would import the model Poll from models/poll.py and Choice from models/choice.py.
     1814Take care that if your models depend on the others you'll need to import them accordingly,
     1815for example, if Poll depends on a ForeignKey to Choice, on poll.py you'd write:
     1816
     1817   from choice import Choice
     1818
    18021819Using models
    18031820============
    18041821
Back to Top