databasedjangooracle-databaseormdjango-custom-field

django - How to make exception for oracle backend in custom field?


THE PROBLEM: I'm writing custom django model field. In get_db_prep_save(self, value, connection) I need to do exception for oracle backend and behave differently from other backends. So I'm looking for the best, official and most elegant way of doing this.

DISCLAIMER: I won't accept answers saying: "use settings.DATABASES and look for django.db.backends.oracle" because it's simply wrong. Using settings I can't figure out which database I'm using currently (default or some other), oracle backend path may change in future from django.db.backends.oracle to something else. What I'm looking for is the best method to check if I'm dealing with oracle when saving custom field to the database.


Solution

  • I hate answering my own questions but I figured out that the correct answer is:

    connection.vendor