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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to