1
\$\begingroup\$

I have a function which checks for a profile name and determines if it is in a tagged profile name.

def check_profiles(request):
try:
    # get all individual profiles
    profiles = Profile.objects.all()
    # get all individual tagged profiles
    tagged_profiles = TaggedProfiles.objects.all()
    # ids to exclude in adding dates
    exclude_profiles = []
    # for profile in profiles
    for profile in profiles:
        # for tagged in sdn list
        for tagged_profile in tagged_profiles:
            # if contains 1
            if any(name in tagged_profile.name_breakdown() for name in profile.name_breakdown()):
                # put in exclude
                exclude_profiles.append(profile.pk)
                profile.status = 'FOR REVIEW'
                profile.save()
                break
    

    for profile in Profile.objects.all().exclude(pk__in = exclude_profiles):
            cleared_dates = profile.cleared_dates
            cleared_dates.append(
                {
                    'date': datetime.now().strftime('%Y-%m-%d'),
                    'time': datetime.now().strftime('%I:%M %p')
                })
            logger.debug(cleared_dates)

            profile.cleared_dates = cleared_dates
            profile.save()
        
except Exception as e:
    logger.error(e)

Basically, if a profile's name is 'firstname lastname', it's breakdown is ['firstname', 'lastname']. And if tagged_profiles include either a 'firstname' or a 'lastname' in any of it's breakdowns, it's a hit.

But I'm doing it very inefficiently. How may I optimize it with any of django's built in functions?

You can see it here.

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.