def make_person(name, building, relation, address=None, city=None, website=None, phone=None): # now associate applicant with building: # first find/make person people = Person.objects.filter(city=city).filter(name=name) person = None # check if a previous building object in the db exists if people.exists(): person = people[0] print "Already had Person: %s" % person.name else: # if not, # CREATE A NEW PERSON OBJECT HERE person = Person() person.name = name if city: person.city = city if address: person.address = address if website: person.website = website if phone: person.phone = phone person.save() # then find/make association: bpeople = BuildingPerson.objects.filter(building=building).filter(person=person) bperson = None # check if a previous building_person object in the db exists if bpeople.exists(): bperson = bpeople[0] print "Already had BuildingPerson: %s with: %s" % (bperson.person.name, bperson.building.address) else: # if not, # CREATE A NEW BUILDING PERSON OBJECT HERE bperson = BuildingPerson() bperson.person = person bperson.building = building bperson.relation = relation bperson.save() return (person, bperson)
def make_person(name, building, relation, address=None, city=None): #now associate applicant with building: #first find/make person people = Person.objects.filter(city=city).filter(name=name) person = None #check if a previous building object in the db exists if people.exists(): person = people[0] print "Already had Person: %s" % person.name else: #if not, #CREATE A NEW PERSON OBJECT HERE person = Person() person.name = name if city: person.city = city if address: person.address = address person.save() #then find/make association: bpeople = BuildingPerson.objects.filter(building=building).filter(person=person) bperson = None #check if a previous building_person object in the db exists if bpeople.exists(): bperson = bpeople[0] print "Already had BuildingPerson: %s with: %s" % (bperson.person.name, bperson.building.address) else: #if not, #CREATE A NEW BUILDING PERSON OBJECT HERE bperson = BuildingPerson() bperson.person = person bperson.building = building bperson.relation = relation bperson.save() return (person, bperson)