Handling SMS replies to register/unregister phone numbers I'm working on a Django Twilio app, and I believe it's coming along well. I just want to improve my code writing skills. How can I improve the below code?

def save_number(request):
    from_number = request.POST.get('From', '')
    try:
        obj = SaveNumber.objects.get(phone_number=from_number)
        if obj == obj:
            subscribe = request.POST.get('Body', )
            if subscribe.lower().strip() == "stellar":
                enter = SaveNumber.objects.get(phone_number=from_number)
                enter.subscribed = True
                enter.save()
                r = twiml.Response()
                r.message("You're in. Always text outtahere, and we'll remove you.")
                return r
            elif subscribe.lower().strip() == "outtahere":
                remove = SaveNumber.objects.get(phone_number=from_number)
                remove.subscribed = False
                remove.save()
    except SaveNumber.DoesNotExist:
        obj = SaveNumber(phone_number=from_number)
        obj.save()
        r1 = twiml.Response()
        r1.message("Reply with stellar and you're in! :-)")
        return r1
Here is my alternative. Your original code calls the DB for the same record twice (potentially) -- the get_or_create does the same as your try/except and creates the record.

def save_number(request):
    from_number = request.POST.get('From', '')
    subscribe = request.POST.get('Body', '').lower().strip()    
    obj, created = SaveNumber.objects.get_or_create(phone_number=from_number)
    response = twiml.Response()

    if created:
        response.message("Reply with stellar and you're in! :-)")
    else:
        if subscribe == "stellar":
            obj.subscribed = True
            obj.save()
            response.message("You're in. Always text outtahere, and we'll remove you.")
        elif subscribe == "outtahere":
            obj.subscribed = False
            obj.save()
            response.message("You're out")
    return response


Disclaimer: i didnt actually test it theyre may be bugs