def add_view(self, *args, **kwargs):
        """
        Redirect to the change view if the singleton instance exists.
        """
        try:
            singleton = self.model.objects.get()
        except (self.model.DoesNotExist, self.model.MultipleObjectsReturned):
            kwargs.setdefault("extra_context", {})
            kwargs["extra_context"]["singleton"] = True
            response = super(SingletonAdmin, self).add_view(*args, **kwargs)
            return self.handle_save(args[0], response)
        return redirect(admin_url(self.model, "change", singleton.id))
def add_view ( self , * args , ** kwargs ) : try : singleton = self . model . objects . get ( ) except ( self . model . DoesNotExist , self . model . MultipleObjectsReturned ) : kwargs . setdefault ( "extra_context" , { } ) kwargs [ "extra_context" ] [ "singleton" ] = True response = super ( SingletonAdmin , self ) . add_view ( * args , ** kwargs ) return self . handle_save ( args [ 0 ] , response ) return redirect ( admin_url ( self . model , "change" , singleton . id ) )
Redirect to the change view if the singleton instance exists.