django check for empty onetoone exists
from django.db import models
class MyModel(models.Model):
# Your fields go here
class AnotherModel(models.Model):
my_model = models.OneToOneField(MyModel, on_delete=models.CASCADE, related_name='another_model')
# Check if MyModel instance has an associated AnotherModel instance
my_model_instance = MyModel.objects.get(pk=1)
has_another_model = hasattr(my_model_instance, 'another_model')