Reputation: 15107
In rails I am able to say:
painting = Painting.first
painting.attributes
And this will automatically display all the model's values. Is there an equivalent in Django to do this?
Upvotes: 0
Views: 374
Reputation: 4213
I didn't understand very well, but if you wanna see all the values from a model use this
list(your_model.objects.values_list())
if you wanna see the fields information use
>>> from django.contrib.auth.models import User
>>> User._meta.get_fields()
(<ManyToOneRel: admin.logentry>,
<django.db.models.fields.AutoField: id>,
<django.db.models.fields.CharField: password>,
<django.db.models.fields.DateTimeField: last_login>,
<django.db.models.fields.BooleanField: is_superuser>,
<django.db.models.fields.CharField: username>,
<django.db.models.fields.CharField: first_name>,
<django.db.models.fields.CharField: last_name>,
<django.db.models.fields.EmailField: email>,
<django.db.models.fields.BooleanField: is_staff>,
<django.db.models.fields.BooleanField: is_active>,
<django.db.models.fields.DateTimeField: date_joined>,
<django.db.models.fields.related.ManyToManyField: groups>,
<django.db.models.fields.related.ManyToManyField: user_permissions>)
read the docs for more information
Upvotes: 3
Reputation: 7873
I don't know about Django in particular, but using python you can try one of the following:
painting.__dict__
vars(painting)
Upvotes: 1