Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14040

Django: Generate random time in a within a specific day and insert multiple rows to database

$
0
0

I have a schedule for user in which it will generate randomly. For example I want to create and schedule for tomorrow, the admin will choose a day and N number of report a day.

So the no_of_route is the # of rows to insert in database and also the # of generated hours and the # of route it will select from RoutePoints class.So, I really don't know to to generate hours. And this is where it should be.

no_of_route = request.POST.get('no_of_route')date = request.POST.get('date')# generate hours, if no_of_route is 3, it would be 9AM, 1PM, 5PMhour = ...

This is how I select random route id.

items = list(RoutePoints.objects.all())random_route = random.sample(items, no_of_route)[0]

And this where I create multiple of rows. I'm not really sure how to do it.

Schedule.objects.bulk_create(route=items.id, time=hour, date=date)

Hope someone see this. Thank you in advance!


Viewing all articles
Browse latest Browse all 14040

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>