List Info

Thread: trying to setup field sets in admin, keep getting error




trying to setup field sets in admin, keep getting error
country flaguser name
United States
2007-03-30 14:36:07
I am trying to setup field sets on my first project,
however, when I
add the admin section below, I get the error "My_blog
has no field
named 'e' " This error goes away if I remove the
"fields=" from below.
I got the code straight from the documentation, what am I
doing
wrong? :

Thanks!

class My_blog(models.Model):
	class Meta:
		verbose_name = "My Blog"

	title = models.CharField(maxlength=100)
	author = models.ForeignKey(User)
	entry = models.TextField()
	published = models.BooleanField()
	entry_date = models.DateTimeField(default=datetime.now)

	def __str__(self):
	        return self.title

	class Admin:
		list_display   = ('title', 'entry_date', 'author',
'published')
		ordering       = ('-entry_date',)

		fields = (
			('normal', { 'fields': ('title', 'author', 'entry',
'published')}),
			('more', { 'classes': 'collapse', 'fields' :
('entry_date') }),
		)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: trying to setup field sets in admin, keep getting error
user name
2007-03-30 14:50:09
On 3/30/07, drackett <drackettgmail.com> wrote:
>                         ('more', { 'classes':
'collapse', 'fields' : ('entry_date') }),

This line is the culprit; change it to

('more', { 'classes': 'collapse', 'fields' : ('entry_date',)
}),

Take note of the comma after 'entry_date'.

The error happens because Django is trying to iterate over
what it
finds in that "fields" entry, and Python allows
you to iterate over a
string just as easily as a tuple, and without the comma it
becomes a
string. And so when Django goes to iterate over it, Python
hands back
the characters in the string, and Django ends up looking for
fields
named "e", "n", "t",
"r", "y", etc.

-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: trying to setup field sets in admin, keep getting error
country flaguser name
United States
2007-03-30 14:58:43
I see.. if there were more than one item in there, the last
comma
isn't necessary anymore, correct?

('more', { 'classes': 'collapse', 'fields' : ('entry_date',
'entry_something') }),


On Mar 30, 2:50 pm, "James Bennett"
<ubernost...gmail.com> wrote:
> On 3/30/07, drackett <drack...gmail.com> wrote:
>
> >                         ('more', { 'classes':
'collapse', 'fields' : ('entry_date') }),
>
> This line is the culprit; change it to
>
> ('more', { 'classes': 'collapse', 'fields' :
('entry_date',) }),
>
> Take note of the comma after 'entry_date'.
>
> The error happens because Django is trying to iterate
over what it
> finds in that "fields" entry, and Python
allows you to iterate over a
> string just as easily as a tuple, and without the comma
it becomes a
> string. And so when Django goes to iterate over it,
Python hands back
> the characters in the string, and Django ends up
looking for fields
> named "e", "n", "t",
"r", "y", etc.
>
> --
> "Bureaucrat Conrad, you are technically correct --
the best kind of correct."


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: trying to setup field sets in admin, keep getting error
user name
2007-03-30 16:04:24
On 3/30/07, drackett <drackettgmail.com> wrote:
> I see.. if there were more than one item in there, the
last comma
> isn't necessary anymore, correct?

Correct. The comma is needed on a single-element tuple so
that Python
can distinguish between something that's in parentheses for
grouping
(e.g., a mathematical expression where you'd want to group
things to
avoid operator precedence) and something that's in
parentheses to be a
tuple.

And technically, the comma is what makes a tuple, not the
parentheses.
For example, this function returns a tuple:

def return_tuple():
    return 'foo', 'bar', 'baz'



-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )