Hello,
Thank you for your answer.
I try : tbData = tableName.objects.values(*strFld.split(","))
but that error appears :
File "/var/lib/python-support/python2.4/django/db/models/sql/query.py", line
1503, in add_fields
field, target, u2, joins, u3, u4 = self.setup_joins(
AttributeError: 'list' object has no attribute 'split'
because strFld.split(",") --> produce a list and in setup_joins try to split a
list raising an error.
-------- Original Message --------
Subject: Re:fields in object.values()
From: Alex Koshelev <[EMAIL PROTECTED]>
To: [email protected]
Date: Sun Dec 07 2008 23:09:32 GMT+0200
Manager's `values` method excepts list of field names but you give the string.
Try this:
tbData = tableName.objects.values(*strFld.split(","))
On Sun, Dec 7, 2008 at 23:48, sotiris.kazakis <[EMAIL PROTECTED]> wrote:
hello,
I search a lot about the use of object.values() but don't get what I
want.
I want to put dynamically (with a string ?) the fields that I want to
get from a model. i.e.:
#model
Class Test(model.Model)
Id = models.AutoField(primary_key=True, verbose_name="a/a")
Name = models.CharField(max_length=90, unique=True,
verbose_name="Name")
Description = models.CharField(max_length=24,
verbose_name="Description")
#function to view the data of my table with strFld
def tbView(tbName,strFld=None):
tableName=eval(tbName) # class instance
tbFields=tableName._meta.fields # load table fields
tbData=tableName.objects.values(strFld) #load only field in
strFld
return render_to_response('myView.html',
{'tbData':tbData,'name':tbName})
I would like to get the data from selected fields with this :
strFld="Name,Description"
tbView('Test',strFld)
When I use that get this error :
raise FieldError("Cannot resolve keyword %r into field. "
FieldError: Cannot resolve keyword 'Name,Description' into field.
Choices are: Id, Name, Description.
What is wrong ?
___________________________________________________________
Χρησιμοποιείτε Yahoo!;
Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail
διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών
μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---