python - AttributeError: 'QuerySet' object has no attribute 'area' -
i got error,attributeerror: 'queryset' object has no attribute 'area' . wanna parse excel , put model(city&prefecture&area&user) . wrote
fourrows_transpose = list(map(list, zip(*fourrows))) val3 = sheet3.cell_value(rowx=0, colx=9) user3 = companyransaction.objects.filter(corporation_id=val3) print(user3) if user3: area = area.objects.filter(name="america") pref = prefecture.objects.create(name="prefecture", area=user3.area) city = city.objects.create(name="city", prefecture=pref) price_u1000 = price.upper1000.objects.get(city=city) price_500_1000 = price.from500to1000.objects.get(city=city) price_u500 = price.under500.objects.get(city=city) pref.name = "ny" pref.save() in range(len(fourrows_transpose)): city.name = fourrows_transpose[i][1] city.save() print(fourrows_transpose[i][1]) price_u1000.name = fourrows_transpose[i][2] price_u1000.save() print(fourrows_transpose[i][2]) price_500_1000.name = fourrows_transpose[i][3] price_500_1000.save() print(fourrows_transpose[i][3]) price_u500.name = fourrows_transpose[i][4] price_u500.save() print(fourrows_transpose[i][4])
models.py is
class area(models.model): name = models.charfield(max_length=20, verbose_name='area', null=true) class user(models.model): user_id = models.charfield(max_length=200,null=true) area = models.foreignkey('area',null=true, blank=true) class prefecture(models.model): name = models.charfield(max_length=20, verbose_name='prefecture') area = models.foreignkey('area', null=true, blank=true) class city(models.model): name = models.charfield(max_length=20, verbose_name='city') prefecture = models.foreignkey('prefecture', null=true, blank=true) class price(models.model): name = models.charfield(max_length=20, verbose_name='price') city = models.foreignkey('city', null=true, blank=true)
i wanna put these data
[['america', '', '', '', ''], ['', '', 'u1000', '500~1000', 'd500'], ['ny', 'city a', '×', '×', '×'], ['', 'city b', '×', '×', '×'], ['', 'city c', '×', '×', '×'], ['', 'city d', '×', '×', '×'], ['', 'city e', '×', '×', '×']]
to models 'america' prefecture's area , city city's name , × to price's name . how can fix this?what should write it?
you seeing error since attempting access .area
on queryset not on single companyransaction
instance. when .filter
queryset returned. if sure single object returned suggest change:
user3 = companyransaction.objects.filter(corporation_id=val3)
to this:
user3 = companyransaction.objects.get(corporation_id=val3)
Comments
Post a Comment