llazzaro / django-scheduler

A calendaring app for Django.
BSD 3-Clause "New" or "Revised" License
1.27k stars 391 forks source link

How to customize GET_EVENTS_FUNC for CalendarByPeriodsView? #549

Open h3x4git opened 1 year ago

h3x4git commented 1 year ago

I need to limit the events displayed by the calendars to the city where the events will take place so I defined a model that inherits directly from Event like this:

from schedule.models import events
from city_app.models import City

class CityEvent(events.Event):
    city = models.ForeignKey(City, on_delete=models.CASCADE)

I hope to be able to serve this events via the same Calendar / Period system that this great package ships with.

I would like to be able to change the way GET_EVENTS_FUNC works inside CalendarByPeriodsView so that it will accept the request, the calendar, and a city object. I think I could just create another mixin CalendarByPeriodsByCityView, passing it a "city" kwarg via the url and define another get_context_data() including a different event_list value (with a custom function) but I'm reading in settings.py comments that GET_EVENTS_FUNC is a callable used to customize the event list given for a calendar and user so I wonder if this could also apply to my situation, is there a clean way to add a parameter to this function without interfering with your code or overriding it?

h3x4git commented 1 year ago

I could painlessly turn the events.Event model of django-scheduler into a polymorphic model for downcasting by simply applying the django-polymorphic directives and migrating. I would suggest this could be a feature request of mine