Code

Opened 5 years ago

Closed 15 months ago

#10134 closed Uncategorized (fixed)

unique_for_* broken?

Reported by: wdoekes Owned by: Alex
Component: Forms Version: 1.4
Severity: Normal Keywords: unique_for_date unique_for_month unique_for_year
Cc: zerok@…, flosch@…, monuszko Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I was looking for the unique_for_date (et al.) implementation to re-use some of it for my own purposes, but I can't seem to find it.

On these pages, I read that one can do the following:
http://docs.djangoproject.com/en/dev/ref/models/fields/#unique-for-date

class Test(models.Model):
    unique_for_date = models.CharField(max_length=128, unique_for_date='date')
    date = models.DateField()

If I read it correctly, it means that when using the admin form (admin.site.register(Test)), I shouldn't be able to enter the same value for unique_for_date for the same date. But instead, the admin form does no uniqueness checking at all.

In [8616] I see that a lot of code that touches the unique_for_* is removed, but I don't see it get added in another place.

Am I missing something?

Attachments (4)

unique_for_stuff.diff (5.7 KB) - added by Alex 5 years ago.
unique_for_stuff.2.diff (5.9 KB) - added by Alex 5 years ago.
unique_for_stuff.3.diff (6.3 KB) - added by Alex 5 years ago.
unique_for_stuff.4.diff (10.9 KB) - added by Alex 5 years ago.
Long function is longer long.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This would be one of the things lost in the move from the old forms/manipulators structure to new forms. The implementation/enforcement of the parameter was removed, but not the ability to specify it, since (I believe) the intent was for the check to only be MIA for as long as model validation (#6845) was missing. Model validation was hoped to be included in 1.0, but unfortunately it is still not in trunk.

Furthermore, from what I can glean of the current implementation at http://github.com/HonzaKral/django/tree/model-validation the check for these parameters is not yet handled by model validation, either, so I'm going to leave this open rather than closing it as a dup of #6845. From what I can tell restoration of checks for parameters like this is not currently covered by #6845, nor do I see it on any of the open issues/todo type pages, so this ticket can serve as a tracker for restoring this function which seems to have slipped through the cracks somewhere. (For anyone more up-to-speed on model validation, if I'm wrong about this bit being missing, or for that matter if I'm wrong about this function intending to be re-supported via model validation, feel free to correct me.)

comment:2 Changed 5 years ago by Alex

Karen you're right about this, I'll add it to the model-validation wiki and bring it up with Honza this evening if he's on.

comment:3 Changed 5 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

I think we need a similar stop-gap to unique_together for unique_for_date in 1.1.

comment:4 Changed 5 years ago by Horst Gutmann <zerok@…>

  • Cc zerok@… added

comment:5 Changed 5 years ago by anonymous

  • Cc flosch@… added

comment:6 Changed 5 years ago by Alex

  • Owner changed from nobody to Alex

comment:7 Changed 5 years ago by Alex

  • Component changed from Database layer (models, ORM) to Forms

Model Validaiton isn't making it in for 1.1 so this is just going to be solved in forms.

Changed 5 years ago by Alex

Changed 5 years ago by Alex

Changed 5 years ago by Alex

Changed 5 years ago by Alex

Long function is longer long.

comment:8 Changed 5 years ago by Alex

That comment was supposed to say, "long function is no longer long" so as to be witty, now I just sound like an idiot :/

comment:9 Changed 5 years ago by Alex

  • Has patch set

comment:10 Changed 5 years ago by jacob

  • Triage Stage changed from Accepted to Ready for checkin

comment:11 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [10646]) Fixed #10134 -- Added unique_for_[date|day|month|year] validation to ModelForm handling. Thanks to Alex Gaynor for the patch.

comment:12 Changed 5 years ago by russellm

(In [10647]) [1.0.X] Fixed #10134 -- Added unique_for_[date|day|month|year] validation to ModelForm handling. Thanks to Alex Gaynor for the patch.

Merge of r10646 from trunk.

comment:13 follow-up: Changed 5 years ago by shannon

does this not also resolve #8377?

comment:14 in reply to: ↑ 13 Changed 5 years ago by kmtracey

Replying to shannon:

does this not also resolve #8377?

Looks like it.

comment:15 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

comment:16 Changed 15 months ago by monuszko

  • Cc monuszko added
  • Easy pickings unset
  • Patch needs improvement set
  • Resolution fixed deleted
  • Severity set to Normal
  • Status changed from closed to new
  • Type set to Uncategorized
  • UI/UX unset
  • Version changed from master to 1.4

I stumbled upon the same problem. 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'.

# 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)

comment:17 Changed 15 months ago by claudep

  • Resolution set to fixed
  • Status changed from new to closed

Please do not reopen bugs fixed 4 years ago. Create a new ticket where you can reference this one, thanks.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.