Thanks for your reply Jacob.  The only problem with the method you
suggested is that the field now shows up in the admin form which
allows people to edit it.  I would rather that this didn't happen.  Is
there any way around this?

Thanks,

Ryan

On Mar 25, 1:54 pm, Jacob Kaplan-Moss <ja...@jacobian.org> wrote:
> Hi Ryan --
>
> On Fri, Mar 25, 2011 at 3:55 AM, Ryan Osborn <ryan.osbor...@gmail.com> wrote:
> > I am using django 1.3 and have the following in my models.py:
>
> > class Entry(models.Model):
> >    title = models.CharField(max_length=255)
> >    slug = models.SlugField(unique_for_date='created')
> >    created = models.DateField(auto_now_add=True, editable=False)
>
> > However, I can add an entry in the admin interface with a slug and
> > then immediately afterwards add another entry with the same slug
> > without an error being rasied.  Am I missing something?
>
> Basically what's happening is that `auto_now_add` and `editable`
> outdated kludges. Both work by actually excluding the field in
> question from the admin form, which means it's not available for
> validation so none is ran.
>
> A better approach, I think, would be to use something like::
>
>     import datetime
>     from django.db import models
>
>     class Entry(models.Model):
>        title = models.CharField(max_length=255)
>        slug = models.SlugField(unique_for_date='created')
>        created = models.DateField(default=datetime.date.today)
>
> This will work as expected in the admin and in model forms.
>
> Jacob

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

Reply via email to