Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ordered field names from peewee Model

Tags:

python

orm

peewee

I'd like to use peewee to create records from a csv. It looks like the syntax requires keyword args:

user = User.create(username='admin', password='test')

If the rows in the csv look like (admin, test), it would be convenient to know the field names ('username', 'password') to form a dict to pass in (it looks like I can't pass in a list of the values for the model to infer what the corresponding fields are).

Is there a property of User that has a list of the field names in the order that they are defined?

Thanks

like image 895
beardc Avatar asked Jun 03 '13 18:06

beardc


1 Answers

Looks like it's User._meta.get_field_names()

I just saw someone else mention it in another question.

like image 155
beardc Avatar answered Oct 26 '22 11:10

beardc