def load(self, request): '''Import a CSV file containing countries.''' countries = request.FILES reader = csv.reader(countries['csv']) for row in reader: c = Country(name=row[0], special=bool(row[1])) c.save() return HttpResponseRedirect(reverse('admin:core_country_changelist'))
def load(self, request): '''Import a CSV file containing countries.''' countries = request.FILES reader = csv.reader( countries['csv'].read().decode('utf-8').splitlines()) for row in reader: special = False if row[1] == '0' or row[ 1] == 'False' or not row[1] else True c = Country(name=row[0], special=special) c.save() return HttpResponseRedirect(reverse('admin:core_country_changelist'))
def new_country(**kwargs): c = Country( name=kwargs.pop('name', 'TestCountry'), special=kwargs.pop('special', False)) c.save() return c
def new_country(**kwargs): c = Country(name=kwargs.pop("name", "TestCountry"), special=kwargs.pop("special", False)) c.save() return c