As a non-specialist Python programmer, I'm looking for feedback on how I extended the get_object method of the Django SingleObjectMixin class.
For most of my detailed views, searching with pk or slugfield is fine, but in some cases I need to get an object based on other (unique) fields, for example. "Username". I subclassed Django DetailView and modified the get_object method as follows:
# extend the method of getting single objects, depending on model def get_object(self, queryset=None): if self.model != mySpecialModel:
Is this a good practice? I try to have one subclass of Detailview that adjusts to different needs when I need to retrieve different objects, but also supports default behavior for ordinary cases. Or is it better to have more subclasses for special occasions?
Thank you for your advice!
Gregor
source share