Example #1
0
def get_state(name, country):
    try:
        s = State.objects.get(name=name, country=country)
    except State.DoesNotExist:
        s = State(name=name, country=country)
        s.save()
    return s
Example #2
0
def get_state(name, country):
    try:
        s = State.objects.get(name = name, country = country)
    except State.DoesNotExist:
        s = State(name = name, country = country)
        s.save()
    return s
Example #3
0
def get_or_create_state(name, country, user_created=False):
    if not country:
        country = 1  # Default to India
    try:
        return State.objects.get(country=country, name=name)
    except State.DoesNotExist:
        if not country:
            return None
        else:
            new = State(name=name, country=country, user_created=user_created)
            new.save()
            return new
    except State.MultipleObjectsReturned:
        return State.objects.filter(country=country, name=name).order_by("id")[0]
Example #4
0
def get_or_create_state(name, country, user_created=False):
    if not country:
        country = 1  # Default to India
    try:
        return State.objects.get(country=country, name=name)
    except State.DoesNotExist:
        if not country:
            return None
        else:
            new = State(name=name, country=country, user_created=user_created)
            new.save()
            return new
    except State.MultipleObjectsReturned:
        return State.objects.filter(country=country,
                                    name=name).order_by('id')[0]