from django.contrib import admin from django_quickbooks import get_realm_model, get_realm_session_model, get_qbd_task_model Realm = get_realm_model() RealmSession = get_realm_session_model() Task = get_qbd_task_model() class RealmAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) if not change: obj.set_password(obj.password) obj.save() admin.site.register(Realm, RealmAdmin) admin.site.register(RealmSession) admin.site.register(Task)
from django.core.exceptions import ObjectDoesNotExist from django.dispatch import receiver from django_quickbooks import get_qbd_task_model, QUICKBOOKS_ENUMS, get_realm_model from django_quickbooks.signals import qbd_task_create QBDTaskModel = get_qbd_task_model() RealmModel = get_realm_model() @receiver(qbd_task_create) def create_qbd_task(sender, qb_operation, qb_resource, object_id, content_type, realm_id, instance=None, *args, **kwargs): try: realm = RealmModel.objects.get(id=realm_id) data = dict(qb_resource=qb_resource, object_id=object_id, content_type=content_type, realm=realm) if QBDTaskModel.objects \ .filter(qb_operation=qb_operation, **data) \ .count(): return