models.py
class Followup(models.Model):
FOLLOWUP_CHOICES = (
(0, 'Not Finished'),
(1, 'Finished')
)
lead = models.ForeignKey(
Lead,
on_delete=models.CASCADE,
related_name='followups'
)
response = models.CharField(
max_length=150,
blank=True, null=True
)
response_number = models.SmallIntegerField(
'Number of given followup response (eg. 1)',
default=1
)
date = models.DateField(auto_now_add=True)
action = models.SmallIntegerField(
choices=FOLLOWUP_CHOICES,
default=FOLLOWUP_CHOICES[0][0] # not finished item's index.
)
recorded_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='recorded_followups'
)
def __str__(self):
return self.lead.name
I have run all migrations locally. Whenever I make some change in my model and I try to run migrations, django complains about this error. There's another case, when I mention this model in the loop of the viewset, Django will raise this exception.
views.py
class FollowupViewSet(viewsets.ModelViewSet):
# I comment from here
followups = Followup.objects.all()
expected_followup_ids = []
lead_names = []
for followup in followups:
if followup.lead.name not in lead_names:
lead_names.append(followup.lead.name)
expected_followup_ids.append(
Followup.objects.filter(lead=followup.lead).last().id
)
else:
continue
queryset = Followup.objects.filter(id__in=expected_followup_ids)
# to here
serializer_class = FollowupSerializer
filter_backends = [DjangoFilterBackend, ]
filterset_fields = ['date', 'recorded_by', 'response']
What's wrong here? How can I run migrations without having caused the error and without commenting on my views.py file's code block?