You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a quite frustrating problem. After fixing a lazyload-issue I now can't delete this model.
Imagine a mixin along with its admin mixin. The ModelAdminMixin overrides get_queryset with a call to select_related; otherwise I'd get a N+1 warning when displaying the related object list or details. This however causes, that I can't delete any of these objects in the admin interface. I will get an eager loading error, wenn pressing delete or the history button of the object. How can I fix that?
In the following you see a boiled down implementation of the mixins and how they are used.
class ModelMixin(models.Model):
created_by = ForeignKey(settings.AUTH_USER_MODEL, on_delete=PROTECT, related_name="created_%(app_label)s_%(class)s")
class Meta:
abstract = True
class ModelAdminMixin(object):
def get_queryset(self, request):
return super(ModelAdminMixin, self).get_queryset(request).select_related('created_by')
They are then used in a concrete model as such:
# models.py
#------------
class ConcreteModel(ModelMixin):
name = models.CharField(_('name'), max_length=100, blank=False, default='undefined')
# admin.py
#-----------
@register(Project)
class ConcreteModelAdmin(ModelAdminMixin, admin.ModelAdmin):
pass
The text was updated successfully, but these errors were encountered:
I have a quite frustrating problem. After fixing a lazyload-issue I now can't delete this model.
Imagine a mixin along with its admin mixin. The ModelAdminMixin overrides
get_queryset
with a call toselect_related
; otherwise I'd get a N+1 warning when displaying the related object list or details. This however causes, that I can't delete any of these objects in the admin interface. I will get an eager loading error, wenn pressing delete or the history button of the object. How can I fix that?In the following you see a boiled down implementation of the mixins and how they are used.
They are then used in a concrete model as such:
The text was updated successfully, but these errors were encountered: