Changes between Version 1 and Version 2 of Ticket #12203, comment 28
- Timestamp:
- Feb 4, 2025, 12:37:41 PM (8 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #12203, comment 28
v1 v2 25 25 > }}} 26 26 27 I tried this solution for modified User and Group and Permission but it didn't work so I ended up with something like this:27 I tried this solution for modified User and Group and Permission but it didn't work, I needed to add auto_created=True in time of checks as well. I also needed to set it back to false after checks or migrations would actually pick it up same as set in the model. 28 28 29 29 The code I ended up with is something like this: 30 30 31 31 {{{ 32 32 class UserAdmin(BaseUserAdmin): 33 34 # TODO(dmu) MEDIUM: Remove `auto_created = True` after these issues are fixed: 35 # https://code.djangoproject.com/ticket/12203 and 36 # https://github.com/django/django/pull/18612 37 def formfield_for_manytomany(self, *args, **kwargs): 38 User.groups.through._meta.auto_created = True # pylint: disable=protected-access 39 User.user_permissions.through._meta.auto_created = True # pylint: disable=protected-access 40 field = super().formfield_for_manytomany(*args, **kwargs) 41 User.user_permissions.through._meta.auto_created = False # pylint: disable=protected-access 42 User.groups.through._meta.auto_created = False # pylint: disable=protected-access 43 return field 44 33 45 def check(self, **kwargs): 34 46 class ThroughModelAdminChecks(self.checks_class): 35 47 def _check_field_spec_item(self, obj, field_name, label): 36 # TODO(dmu) MEDIUM: Remove `auto_created = True` after these issues are fixed:37 # https://code.djangoproject.com/ticket/12203 and38 # https://github.com/django/django/pull/1861239 48 User.user_permissions.through._meta.auto_created = True # pylint: disable=protected-access 40 49 User.groups.through._meta.auto_created = True # pylint: disable=protected-access … … 43 52 User.groups.through._meta.auto_created = False # pylint: disable=protected-access 44 53 return result 54 45 55 return ThroughModelAdminChecks().check(self, **kwargs) 46 56