{{{
class CustomUser(models.User):
is_deleted = models.BooleanField(default=False)
def __bool__(self):
return not self.is_deleted
}}}
the `UserAdmin` will use `add_fieldsets` because of comparison in
`get_fieldsets`.
I have a simple fix for this: just check against `None` instead of boolean
evaluation.
--
Ticket URL: <https://code.djangoproject.com/ticket/31472>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "fix.patch" added.
* owner: nobody => krnr
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31472#comment:1>
* type: Bug => Cleanup/optimization
--
Ticket URL: <https://code.djangoproject.com/ticket/31472#comment:2>
* status: assigned => closed
* resolution: => wontfix
Comment:
I know that this fix is quite small but you will find other places where
we use `if instance/obj` pattern, e.g. in `SingleObjectMixin`. Defining
`__bool__` on a model instance is an edge case and your issue can be
worked around by defining and using e.g. `is_active(self): return not
self.is_deleted`. See also
[https://code.djangoproject.com/ticket/29893#comment:4 arguments] for
closing a similar ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/31472#comment:3>
Comment (by krnr):
I was fine with the existing admin class (because I seldom meet such user
models), but recently I saw this PR:
https://github.com/django/django/commit/5cd4c3e5595128bc1a3f28f2e30bab2e4dd3b1b7
and I was thinking "why does it have nice check against None in one method
and doesn't have in another?"
and it's not about checking against all possible `if instance` (yeah, it
doesn't worth it), just about fieldsets.
but that's OK. just leave it be if anyone else will be curious.
--
Ticket URL: <https://code.djangoproject.com/ticket/31472#comment:4>