unique_for_ fields

10 views
Skip to first unread message

oggie rob

unread,
Sep 28, 2008, 6:07:18 PM9/28/08
to Django developers
Hi all,
unique_for_date (and for_month, for_year as well) are not functional
in 1.0, but before I try to get them working, I'm wondering if there
is any thought about those fields.

Currently they are included in the model field definition, but of
course the documentation mentions that it is used for validation only
at the "admin-form level". Is there a plan to either provide model-
aware validation (hmm, that does sound familiar...) or deprecate these
options and move them to the ModelAdmin class? Or if there isn't a
clear path, what are the recommendations? (It seems like a pretty
handy feature so I think it should be reinstated.)

There is a ticket open on this: http://code.djangoproject.com/ticket/8377

-rob

Malcolm Tredinnick

unread,
Sep 28, 2008, 8:02:05 PM9/28/08
to django-d...@googlegroups.com

On Sun, 2008-09-28 at 15:07 -0700, oggie rob wrote:
> Hi all,
> unique_for_date (and for_month, for_year as well) are not functional
> in 1.0, but before I try to get them working, I'm wondering if there
> is any thought about those fields.
>
> Currently they are included in the model field definition, but of
> course the documentation mentions that it is used for validation only
> at the "admin-form level". Is there a plan to either provide model-
> aware validation (hmm, that does sound familiar...)

Short version: model-aware validation is being worked on. We didn't get
it finished for 1.0, but it's still ongoing work.

Malcolm


oggie rob

unread,
Sep 28, 2008, 8:44:58 PM9/28/08
to Django developers
On Sep 28, 5:02 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> Short version: model-aware validation is being worked on. We didn't get
> it finished for 1.0, but it's still ongoing work.

Great! Judging by the activity this is tracked in #6845 so I included
a note and a reference in the ticket (and will wait instead of trying
to fix it now).

-rob

David Danier

unread,
Oct 1, 2008, 4:28:55 AM10/1/08
to django-d...@googlegroups.com
> Short version: model-aware validation is being worked on. We didn't get
> it finished for 1.0, but it's still ongoing work.

Wouldn't it be nice to replace these three parameters by something like:
class SomeModel(models.Model):
[...]
class Meta:
unique_together = ('title', 'pub_date__year')

Meaning we could use the same syntax as we do for filter()/explude().

This could allow new use-cases like some combination of fields should be
unique for some given date. Example:
class SomeCategorizedModel(models.Model):
[...]
class Meta:
# perhaps useful for urls like /foo/<year>/<category>/<slug>/
unique_together = ('slug', 'category', 'pub_date__year')


Just some ideas I had when reading the original post, don't know if this
would require lots of work. :)

Greetings, David Danier

Reply all
Reply to author
Forward
0 new messages