'Delete PostgreSQL foreign keys and constraints tracked by this model.'

@api.multi
def _module_data_uninstall(self):

    if (not ((self._uid == SUPERUSER_ID) or self.env.user.has_group('base.group_system'))):
        raise AccessError(_('Administrator    access    is    required    to    uninstall    a    module'))
    ids_set = set(self.ids)
    for data in self.sorted(key='id', reverse=True):
        name = tools.ustr(data.name)
        if (data.model.model in self.env):
            table = self.env[data.model.model]._table
        else:
            table = data.model.model.replace('.', '_')
        typ = data.type
        self._cr.execute('SELECT    id    from    ir_model_constraint    where    name=%s', (data.name,))
        external_ids = set((x[0] for x in self._cr.fetchall()))
        if (external_ids - ids_set):
            continue
        if (typ == 'f'):
            self._cr.execute('SELECT    1    from    pg_constraint    cs    JOIN    pg_class    cl    ON    (cs.conrelid    =    cl.oid)\n                                                                                                                                                WHERE    cs.contype=%s    and    cs.conname=%s    and    cl.relname=%s', ('f', name, table))
            if self._cr.fetchone():
                self._cr.execute(('ALTER    TABLE    "%s"    DROP    CONSTRAINT    "%s"' % (table, name)))
                _logger.info('Dropped    FK    CONSTRAINT    %s@%s', name, data.model.model)
        if (typ == 'u'):
            self._cr.execute('SELECT    1    from    pg_constraint    cs    JOIN    pg_class    cl    ON    (cs.conrelid    =    cl.oid)\n                                                                                                                                                WHERE    cs.contype=%s    and    cs.conname=%s    and    cl.relname=%s', ('u', name, table))
            if self._cr.fetchone():
                self._cr.execute(('ALTER    TABLE    "%s"    DROP    CONSTRAINT    "%s"' % (table, name)))
                _logger.info('Dropped    CONSTRAINT    %s@%s', name, data.model.model)
    self.unlink()
