示例#1
0
 def create(self, submitter):
     if self._instance is not None:
         message = "Failed to create resto: this form is bound to an existing resto."
         raise ProgrammingError(message)
     if not self.is_valid():
         raise InvalidFormError(self.errors)
     instance = Resto.create(submitter=submitter, **self.cleaned_data)
     instance.save()
     return instance
示例#2
0
 def create_instance(self, csv_row):
     name = csv_row[0].strip()
     category = csv_row[7].strip()
     if category not in self.categories:
         return None
     city = csv_row[3].strip()
     if city != u"巴黎":
         return None
     city = u"Paris"
     address = csv_row[1].strip()
     route = csv_row[2].strip()
     tel_1 = csv_row[4].strip() or None
     resto = Resto.create(
         name=name,
         category=category,
         address=address,
         route=route,
         city=city,
         tel_1=tel_1,
         submitter=self.submitter
     )
     return resto