Samir Tendulkar
Samir Tendulkar

Reputation: 1191

Making a function in a app that changes fields in another app

Hi Djangonauts, I am new to Django so please forgive any errors in logic or code I have a accounts app that has a Profile model with a field is_verified Now I have another app called verification. That has a model Verification and a field called verify I want to create a logic such that when you verify the user on the verification app. The is_verified on profile app is also marked as True

models.py for Profile

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    city = models.CharField(max_length=100)
    country = models.CharField(max_length=100)
    is_verified = models.BooleanField(default=False)

models.py for Verification

class Verification(models.Model):
    user = models.ForeignKey(User, related_name='verified')
    applied_on = models.DateTimeField(auto_now_add=True)
    verify = models.BooleanField(default=False)
    deny = models.BooleanField(default=False)
    verified_on = models.DateTimeField()
    denied_on = models.DateTimeField()

    def verify_a_user(self, user):
        self.verify = True
        user.profile.is_verified = True
        return user.profile.is_verified.save() 

Is this correct? Is there a better way to execute this code

Upvotes: 0

Views: 29

Answers (1)

Related Questions