membershipworks: Use bulk_create for Event
All checks were successful
Ruff / ruff (push) Successful in 21s

Work around for issues with GeneratedField. Also faster anyway.
This commit is contained in:
Adam Goldsmith 2024-01-24 18:35:25 -05:00
parent e0b5820bc2
commit ee399e6b64

View File

@ -115,12 +115,23 @@ def scrape_events():
category.clean_fields() category.clean_fields()
category.save() category.save()
for event_data in data["evt"]: events = Event.objects.bulk_create(
logger.debug(event_data) [Event.from_api_dict(event_data) for event_data in data["evt"]],
event = Event.from_api_dict(event_data) update_conflicts=True,
event.clean_fields() update_fields=[
event.save() field.attname
for field in Event._meta.get_fields()
if not (
field.auto_created
or field.many_to_many
or not field.concrete
or field.generated
or field.primary_key
)
],
)
for event in events:
try: try:
event_ext = EventExt.objects.get(event_ptr=event) event_ext = EventExt.objects.get(event_ptr=event)
except EventExt.DoesNotExist: except EventExt.DoesNotExist: