python 3.x - Defining django models in an alphabetic order -
can define django models in alphabetic order?
models taken django tutorial:
from django.db import models class question(models.model): question_text = models.charfield(max_length=200) pub_date = models.datetimefield('date published') class choice(models.model): question = models.foreignkey(question) choice_text = models.charfield(max_length=200) votes = models.integerfield(default=0)
i'd choice
defined before question
. after simple reordering
class choice(models.models): question = models.foreignkey(question) question = models.foreignkey(question) choice_text = models.charfield(max_length=200) votes = models.integerfield(default=0) class question(models.models): question_text = models.charfield(max_length=200) pub_date = models.datetimefield('date published')
fails, because need question
before telling interpreter is.
adding simple empty
class choise(models.model): pass class question(models.model): pass
causes django scream , still fail python manage.py makemigrations polls
.
is there hack define models in alphabetical order?
or should forfeit idea , define totally unrelks ated related everything?
note: according sayse, workarounds break ides in ide can't know whether mean literal string or if looking class.
if need create relationship on model has not yet been defined, can use name of model, rather model object itself:
question = models.foreignkey('question')
instead of
question = models.foreignkey(question)
from https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.foreignkey
Comments
Post a Comment