[Fixed]-Django Serialize to Json from Super class

1👍

Django has a built in serializer documented here but it might not work as well considering how you structured your models:

from django.core import serializers
data = serializers.serialize("json", CampaignContactCompany.objects.all())

I imagine you could run that on both tables and combine the two sets but it would introduce a bit of overhead. You could also create a static to_json method in CampaignContact which takes two query sets from the other two tables and formats/combines them into json.

Maybe you have reason to model your tables as you did but based on observation it looks like you will have 3 tables, one never used and two with only a company and lead field different which is probably not ideal. Typically when relating a record to multiple objects you would simply put the lead and company field on the CampaignContact table and let them be null. To get only company contacts you could query company_contacts = CampaignContact.objects.filter(company__isnull=False).all()

Leave a comment