Admin refuses to save on an unspecified error

291 views
Skip to first unread message

RCRam...@gldd.com

unread,
Oct 24, 2005, 7:37:12 AM10/24/05
to django...@googlegroups.com
I have a weblog app (definition of the Post object below). Everything looks OK, but when I go to add or edit a post, the admin app will not let me. I make my changes (or fill in the fields for a new post). The server reports that it is POSTing the HTML:

[24/Oct/2005 06:23:01] "POST /admin/weblog/posts/add/ HTTP/1.1" 200 4845

But then admin comes back with the same edit screen saying 'Please correct the error below.' across the top, but not specifying the error. I tried saving a post with intentional errors (no title or non-unique title), and the admin correctly notified me of the error.

Any idea where I should look or why this message is appearing?

Robert

class Post(meta.Model):
pub_date = meta.DateTimeField(default=meta.LazyDate())
author = meta.ForeignKey(Author)
title = meta.CharField(maxlength=50, unique=True)
text = meta.TextField()
category = meta.ForeignKey(Category)
slug = meta.SlugField(prepopulate_from=("title",))

class META:
admin = meta.Admin(
fields = (
(None, {'fields': ('title', 'pub_date', 'author')}),
('Contents', {'fields': ('category', 'text')}),
),
list_display = ('title', 'author', 'pub_date', 'category'),
list_filter = ['pub_date', 'author', 'category'],
date_hierarchy = 'pub_date',
)

def __repr__(self):
return self.slug
winmail.dat

Malcolm Tredinnick

unread,
Oct 24, 2005, 7:58:53 AM10/24/05
to Django users

It is because of the 'slug' field and the fact that you are not showing
it on the entry form.

The 'prepopulate_from' attribute forces the inclusion of some
Javascript into the admin view page to fill in that field. However,
because you are not displaying the field on the page (the 'fields'
parameter does not include it) it does not get populated via Javascript
and you have not set blank = True. Hence the validation fails. The
slightly strange error display is because you are not showing the field
that is the problem.

Cheers,
Malcolm

RCRam...@gldd.com

unread,
Oct 24, 2005, 7:13:58 PM10/24/05
to django...@googlegroups.com
That was it. Thanks. However, there is a new wrinkle. When I update the post using the admin interface, the history tells me that the 'pub_date' has been changed, even though I did not change it, and it still looks the same in the admin interface. Is this a rounding error connected to the default date and time? The second time I edit the date is not listed as changed.

Robert
winmail.dat

Adrian Holovaty

unread,
Oct 24, 2005, 7:39:50 PM10/24/05
to django...@googlegroups.com
On 10/24/05, RCRam...@gldd.com <RCRam...@gldd.com> wrote:
> When I update the post using the admin interface, the history tells me that the
> 'pub_date' has been changed, even though I did not change it, and it still looks
> the same in the admin interface. Is this a rounding error connected to the
> default date and time? The second time I edit the date is not listed as changed.

You're correct -- this is a rounding error connected to the default
date/time. The default date/time is set to datetime.datetime.now(),
which is accurate to the millisecond (or maybe even microsecond?)
level, whereas editing the date/time value via the form field is only
accurate to the second. So Django things the value has changed.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org
Reply all
Reply to author
Forward
0 new messages