Django, relating model to another app models field

First off this may not be the best way to set this up, however, I'm learning as I go and struggling to find the correct answer.

I have an Account app which handles the user signup, I added the couple_choice option which I'm trying to get in another app's model.

ACCOUNT model

class Account(AbstractBaseUser):
    COUPLE_CHOICE = Choices('single', 'couple')

    email                   = models.EmailField(verbose_name="email", max_length=60, unique=True)
    username                = models.CharField(max_length=30, unique=True)
    date_joined             = models.DateTimeField(verbose_name='date joined', auto_now_add=True)
    last_login              = models.DateTimeField(verbose_name='last login', auto_now=True)
    is_admin                = models.BooleanField(default=False)
    is_active               = models.BooleanField(default=True)
    is_staff                = models.BooleanField(default=False)
    is_superuser            = models.BooleanField(default=False)
    profile_image           = models.ImageField(max_length=255, upload_to=get_profile_image_filepath, null=True, blank=True, default=get_default_profile_image)
    hide_email              = models.BooleanField(default=True)
    couple_choice           = models.CharField(choices=COUPLE_CHOICE, default='single', max_length=20)

I then have another app Profile, which I want to make the couple = to the Account.account.couple_choice, or if the Account.couple.choice is 'couple' then Profile.couple = True

from account.models import Account

class Profile(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,blank=True, null=True, related_name="swinger")
    couple = models.ManyToManyField(Account, to_field="couple_choice", blank=True, null=True,related_name="is_couple", on_delete=models.CASCADE)

PLease let me know the best way to do this? Thanks

if you set the Profile.couple = True, you must define couple as boolean. To achieve your aim, you should control the Account.couple_choise when user save profile. You can do this if you have ModelAdmin class in admin.py like

@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
     def save_model(self, request, obj, form, change):
        if Account.objects.filter(email=request.user.email).exists()
            account = Account.objects.get(email=request.user.email)
            if account.couple_choice == 'couple'
                obj.couple = True
        super().save_model(request, obj, form, change)
Back to Top