# Value is probably a queryset - but allow any iterable.
# These lines shouldn't be necessary; however, if value is an EmptyQuerySet,
- # the code won't work without them. Unclear why...
+ # the code (specifically the object_id__in query) won't work without them. Unclear why...
if not value:
value = []
+ # Before we can fiddle with the many-to-many to foreignkeyvalues, we need
+ # a pk.
+ if self.pk is None:
+ self.save()
+
if isinstance(value, models.query.QuerySet):
value = value.values_list('id', flat=True)