I have a semi large software. At one point I included tables2 into that project and started to work with it. I the filter.py file I included some basic Model filtering. Now if I delete my database and try to run a fresh migrations I get the error, that this table is not avaible. I builded a try catch around and it's working since it does not run the code snipped before the migration.
class PracticephaseProjectFilter(django_filters.FilterSet):
omni = django_filters.CharFilter(method=omni_search, label="Suche")
practice_phase = django_filters.ModelChoiceFilter(queryset=PracticePhase.objects.filter(pk__in=get_pp_for_specialpermit()))
class Meta:
model = PracticePhaseProject
fields = ['practice_phase']
def __init__(self, *args, **kwargs):
super(PracticephaseProjectFilter, self).__init__(*args, **kwargs)
def get_pp_for_specialpermit():
pp = []
today = date.today()
# check if SS or WS required
if 4 <= today.month <= 9:
# current SS, project will be sought for WS this year
pp_str = [str(today.year)[-2:] + "s", str(today.year - 1)[-2:] + "w"]
# we are in WS, check correct year for SS
elif today.month > 9:
pp_str = [str(today.year)[-2:] + "w", str(today.year)[-2:] + "s"]
# we are allready in the year of next SS
else:
pp_str = [str(today.year - 1)[-2:] + "s", str(today.year - 1)[-2:] + "w"]
try:
for _pp in PracticePhase.objects.filter(semester__name__in=pp_str):
pp.append(_pp.pk)
except:
pass
return pp
Now if I remove the try catch around the for loop I cannot run the migrations since I get on database error that there is no table practicephase. But the file should never be called before migration.