Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-meta-whatsapp/llms.txt

Use this file to discover all available pages before exploring further.

django-meta-whatsapp stores WhatsApp contacts in its own WhatsAppContact model but provides three patterns for linking to your existing Django User model — choose the one that fits your architecture.
Create a thin profile model with OneToOneField relationships to both User and WhatsAppContact. This is the most flexible approach as it lets you query in either direction — from a user to their WhatsApp contact, and from a contact back to your application user.
myapp/models.py
from django.conf import settings
from django.db import models
from django_meta_whatsapp.models import WhatsAppContact

class UserWhatsAppProfile(models.Model):
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name="whatsapp_profile"
    )
    contact = models.OneToOneField(
        WhatsAppContact,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="user_profile"
    )
Then link the profile on registration or profile update:
from django_meta_whatsapp.models import WhatsAppContact
from myapp.models import UserWhatsAppProfile

def link_user_to_whatsapp(user, phone_number):
    contact, _ = WhatsAppContact.objects.get_or_create(
        phone=phone_number,
        defaults={"name": user.get_full_name()}
    )
    UserWhatsAppProfile.objects.update_or_create(
        user=user,
        defaults={"contact": contact}
    )
Once linked, you can traverse the relationship in both directions:
# User → Contact
contact = request.user.whatsapp_profile.contact

# Contact → User
user = some_contact.user_profile.user

Choosing a Pattern

Best when you need to query in both directions — from a contact back to a user, and from a user to their contact. Use this if you need to display the Django user’s details in the inbox, or if you want to enforce a strict one-to-one relationship enforced at the database level.
Best when you only need campaign sends and don’t need bi-directional linking. If all you want is to send bulk template messages to a slice of your user base, returning a filtered queryset is the fastest path with zero schema migrations.
Best for passive sync where contacts should always mirror your user database. Choose this when you want the WhatsAppContact table to automatically stay current as users register, update their profiles, or add phone numbers — without any explicit linking calls in your application code.

Build docs developers (and LLMs) love