[Django] #20228: Admin interface doesn't prevent duplicates with unique_for_date

10 views
Skip to first unread message

Django

unread,
Apr 9, 2013, 4:17:25 AM4/9/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+--------------------
Reporter: monuszko | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I'm using Python 2.7.3 and Django 1.4.5-1 from Debian repositories. I can
add multiple entries with identical values and the admin interface doesn't
complain. I tried with both 'slug' and 'title'.
It sounds just like the bug from 4 years ago:
https://code.djangoproject.com/ticket/10134

Note that while my field is DateTimeField (with time), the wording of the
description at
https://docs.djangoproject.com/en/dev/ref/models/fields/#unique-for-date
leads me to believe it should consider only the .date component of the
DateTimeField.


{{{

# models.py

from django.db import models

from django.utils.timezone import now as utcnow
now = utcnow() # replacing - date.now() causes problems with auto_now_add

class Entry(models.Model):
created_at = models.DateTimeField(default=now, editable=False)
title = models.CharField(max_length = 50)
content = models.TextField()
slug = models.SlugField(unique_for_date='created_at')

def __unicode__(self):
return self.title
class Meta:
ordering = ['-created_at']

# admin.py

from news.models import Entry
from django.contrib import admin

class EntryAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}

list_filter = ['created_at']
date_hierarchy = 'created_at'

admin.site.register(Entry, EntryAdmin)

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20228>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 9, 2013, 12:39:56 PM4/9/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------

Reporter: monuszko | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

I guess it currently does `unique_for_datetime` when used on a
DateTimeField.

Changing to operate only on the date part is backwards incompatible, but
I've already made a bunch of similar cleanups, I suppose we can do one
more.

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:1>

Django

unread,
Apr 11, 2013, 2:57:44 AM4/11/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------

Reporter: monuszko | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by monuszko):

Either way, functionality should match the documentation. To my
understanding of English, it currently doesn't. An extra sentence for
clarification of DateTimeField would be nice. I can't evaluate how
important backwards compatibility is in this case, but from programmer
convenience point of view it would be very nice to have unique_for_date
only consider the .date component. "unique_for_datetime" can already be
achieved with unique_together.

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:2>

Django

unread,
May 20, 2013, 6:43:55 PM5/20/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------

Reporter: monuszko | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by svisser):

This seems similar to #18427; fixing one may also provide a stepping stone
to fixing the other.

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:3>

Django

unread,
May 21, 2013, 2:26:53 PM5/21/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------

Reporter: monuszko | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by iapain):

* component: Uncategorized => contrib.admin


Comment:

It looks like valid bug. Fortunately, it's limited to contrib.admin. I was
unable to repeat this in ModelForms, Forms and Model Validation.

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:4>

Django

unread,
May 21, 2013, 2:27:30 PM5/21/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------
Reporter: monuszko | Owner: iapain
Type: Bug | Status: assigned

Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by iapain):

* owner: nobody => iapain
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:5>

Django

unread,
May 21, 2013, 5:14:30 PM5/21/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------
Reporter: monuszko | Owner: iapain
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by iapain):

The reason for this is validate_unique skips "created_at" because it's
internally in excluded fields since it's not rendered in admin UI.

@aaugustin Shouldn't we check f.name instead of f.unique_for_* in
https://github.com/django/django/blob/master/django/db/models/base.py#L800-L804
? If not then we should mark it as documentation bug and add a note in
documentation that field should not be excluded.

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:6>

Django

unread,
May 21, 2013, 5:15:05 PM5/21/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------------+-------------------------------------

Reporter: monuszko | Owner: iapain
Type: Bug | Status: assigned
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by iapain):

* component: contrib.admin => Database layer (models, ORM)


--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:7>

Django

unread,
May 24, 2013, 6:02:20 PM5/24/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------

Reporter: monuszko | Owner: iapain
Type: Bug | Status: assigned
Component: Documentation | Version: 1.4

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by iapain):

* has_patch: 0 => 1
* component: Database layer (models, ORM) => Documentation


Comment:

https://github.com/django/django/pull/1215

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:8>

Django

unread,
May 28, 2013, 10:04:36 AM5/28/13
to django-...@googlegroups.com
#20228: Admin interface doesn't prevent duplicates with unique_for_date
-------------------------------+------------------------------------
Reporter: monuszko | Owner: iapain
Type: Bug | Status: closed
Component: Documentation | Version: 1.4
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d321d1acf0fdf00247e78b9686be84c18b35b9d8"]:
{{{
#!CommitTicketReference repository=""
revision="d321d1acf0fdf00247e78b9686be84c18b35b9d8"
Fixed #20228 - Documented unique_for_date and exclude behavior.

Thanks Deepak Thukral for the patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20228#comment:9>

Reply all
Reply to author
Forward
0 new messages