-1

Lets say I have two models. User and Post. I am iterating over the users and updating few fields lets day likes, dislike etc. The problem is, when I pass the likes n dislikes as integer, it is getting assigned as tuple and its causing issue while saving the record.

Following is the code I tried (Minimal example):

like = 123
dislike = 456
for user in users:
    post = user.post
    post.like = like # for now lets consider it as float field
    post.dislike = dislike
    post.save()

It produces the error as TypeError: float() argument must be a string or a number, not 'tuple'

Also, I checked the This question which sounds similar, but it is not answered yet.

Any suggestions whould be helpful.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
lazy_coder
  • 13
  • 4

1 Answers1

0

It seems like Peewee is working just fine:

db = SqliteDatabase(':memory:')

class Post(db.Model):
    like = FloatField()
    dislike = FloatField()

db.create_tables([Post])

p = Post()
p.like = 123
p.dislike = 456
p.save()

for p in Post:
    print(p.like, p.dislike)

The output is, correctly:

123.0 456.0
coleifer
  • 24,887
  • 6
  • 60
  • 75