I'm new to Django and I'm trying to use django-schedule to my first project. I couldn't figure out how to change the following code to display all events in all calendars:
get_events(request, calendar):
return calendar.event_set.all()
The code above simply displays all events of one particular calendar.
Thanks in advance!
Use:
from schedule.models import Event
Event.objects.all()
Related
I have a field in one of my models in django which I want to be reset every hour.
(i.e. at each o'clock its value becomes zero)
How can I do this task? Can I schedule a function in django?
As you know we can define EVENTs and TRIGGERs in mysql and other database backend. Also I am familiar with signals in django but those can not fit in my needs. (because database event is somewhat outside of django and have problems; with signals although it seems this is impossible!)
You could use schedule, it's very easy to apply for your problem.
import schedule
import time
def job():
print("I'm working...")
schedule.every().hour.do(job)
while True:
schedule.run_pending()
time.sleep(1)
Here there is a thread where it is shown how to execute a task periodically. Then you could add some conditions to fit your scenario.
Did a small app for parking and i want to ask your advice/help on how to make an automation that will submit daily report to the admin.
Currently use Dango SQL-Explorer 3rd pty plugin to show you this.
Basically my SQL query is:
SELECT *
FROM parcare_parking
WHERE parking_on = tomorrow()
In the explorer i can see nice this window. I would like each day at 18:00 to receive the snapshot of this query. How can i do that?
Two things
Add a Django template that generates the output in the desired tabular form
For scheduling the task to run periodically, add an entry to the cron list. eg wget http://yourdomain.com/your-route
Or use Django Celery http://docs.celeryproject.org for periodic execution (A more robust package)
I want to implement a feature where you can select a date for when a post can go public in the Django admin. Is there a way we can set this in Django? What's the best practice to do this?
You're thinking along the wrong lines. Instead of having a status flag which is flipped at a certain time, which would involve cron jobs, you only need a single publish_at field - then your front end can show all the posts with publish_at before now.
I am trying to set up a system where every time something happens in the admin console (let's say, a user is saved), a certain set of people gets notified. I hooked up post_save and
it works fine. I can retrieve most of the data I need (which user and what fields were saved) from the instance passed into the callback function. However, there's one thing in the requirements, which I can't figure out how to do and that is to show, which particular admin made the change. Any ideas on how that can be done?
Thank you,
Luka
If you go through the database, you will discover that you have the table django_admin_log which lists what changes were made by what admin and even has a change_message . Maybe you can create a view for this table and play around with the queries.
Is there a way to have a django Clandar Event, i have a Event model, and i want to display the event information on the calendar in order to know if the organiser is free or busy on the date event.
Many Thanks.
I didn't find the Django Calendar.
Where can i find some good example please ?
Many thanks
Search the site and you might just find what you're looking for.