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
Post a Comment