The easiest way is to do it in admin
Your models
class Event(models.Model): event_dates = ManyToManyField("EventDate")
Now in your admin file
This has the added benefit that it only returns dates for the current event that you are watching, using the reverse lookup event__id=event_id
class EventAdmin(admin.ModelAdmin): def get_field_queryset(self, db, db_field, request): """ If the ModelAdmin specifies ordering, the queryset should respect that ordering. Otherwise don't specify the queryset, let the field decide (returns None in that case). """ if db_field.name == 'event_dates': event_id = int(request.resolver_match.args[0]) return db_field.remote_field.model._default_manager.filter( event__id=event_id, event_date__gte = datetime.date.today() ) super().get_field_queryset(db, db_field, request)
source share