python - how to make django module fully independent? -


look @ model class

from django.db import models meeting.models import meeting  # create models here.   class agenda(models.model):     name = models.charfield(max_length=255)     meeting = models.foreignkey(meeting, on_delete=models.protect)     priority = models.integerfield() 

here agenda, class needs meeting class foreign key. possible agenda class work if importing meeting class fail. if meeting class not found create default meeting object.

you can conditionally, heavy caveats break , break between server restarts.

from django.db import models try:     meeting.models import meeting     has_meetings = true except:     has_meetings = false  # create models here.   class agenda(models.model):     name = models.charfield(max_length=255)     if has_meetings:         meeting = models.foreignkey(meeting, on_delete=models.protect)     priority = models.integerfield() 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -