Hi there,
I'm kind of a novice in django and like to call rfm_update before the get request in the RFM Viewset will executed,
but no surprise the migrate doesn't work for a new deployment.
What is the best practice to do something like rfm_update so that migrate works.
Thanks in advance,
Christian
def rfm_update():
rfms = RFM.objects.all()
rfms.delete()
df_rfm = pd.DataFrame(list(Order.objects.all().values()))
rfm_data = processing(df_rfm, datetime_col='order_datetime', customer_id_col='customer_id').reset_index()
RFM.objects.bulk_create([RFM(customer_id=rec[0],
frequency=rec[1],
recency=rec[2],
T=rec[3]) for rec in rfm_data.values])
class RFMViewSet(viewsets.ModelViewSet):
rfm_update() # Not good!
queryset = RFM.objects.all()
serializer_class = RFMSerializer
lookup_field = 'customer_id'
http_method_names = ['get']