I have been tasked with adding some new functionality to an existing view. Basically, on user signup if the company is already in the database, I am sending an email to an admin, saying “User wants to claim company”. If admin approves, that user will be added to the company, and I want to override the previous info (address, phone, etc.) with the info this user put in at registration. I thought the best way to do this was to add a field to the
Account model, called
is_approved and set it to
False , and when the admin approves, they will set it to
True and the new info will be stored, overriding the existing data. I have a
Company model, and a
Pending_Company model, both with the same exact info.
company_obj = Company.objects.filter(I am filtering the DB here) if not company_obj: """If no company match, create new one""" new_company = Company.objects.create( name=company.title(), zip=int(zip_code), primary_email=email, website=website, phone_no=phone_no, street=street, city=city, state=state, ) new_company.owner.add(user) else: """Add employee to company, send email to admin for approval, if approved, update company instance with new data.""" # If DEBUG = True send_mail('Test Subject', 'Test message', 'firstname.lastname@example.org', ['email@example.com', ], fail_silently=False) pending_company = PendingCompanyDetail.objects.create( name=company.title(), zip=int(zip_code), primary_email=email, website=website, phone_no=phone_no, street=street, city=city, state=state, ) pending_company.owner.add(user) if user.is_approved: company_obj = pending_company
else statement is where I am getting confused, It is not updating the
company_obj instance with the new
I kind of understand why, because on account creation the
is_approved is defaulted to
False . I’m really trying to figure out a work around for this, when that boolean is flipped to
True , how can I trigger that override?