Django

Code

Ticket #10769 (closed: duplicate)

Opened 1 year ago

Last modified 1 year ago

IntegrityError with generic relations, unique_together, and inline admin forms

Reported by: rutt Assigned to: nobody
Milestone: 1.1 Component: django.contrib.admin
Version: 1.1-beta-1 Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Using the models and admin below, create a new GenericAttachment object using the inline form on the Parent change page. Then create another one with the same slug. The result is an IntegrityError where "columns content_type_id, object_id, slug are not unique". This works fine for Attachment objects.

Models:

class Parent(models.Model):
    name = models.CharField(max_length=200)
    
class Attachment(models.Model):
    name = models.CharField(max_length=200)
    parent = models.ForeignKey(Parent)
    slug = models.SlugField()
    
    class Meta:
        unique_together = ['parent', 'slug']
    
class GenericAttachment(models.Model):
    name = models.CharField(max_length=200)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    parent = generic.GenericForeignKey()
    slug = models.SlugField()
    
    class Meta:
        unique_together = ['content_type', 'object_id', 'slug']

Admin:

class GenericAttachmentInline(generic.GenericTabularInline):
    model = GenericAttachment
    
class ParentAdmin(admin.ModelAdmin):
    inlines = [AttachmentInline, GenericAttachmentInline]

admin.site.register(Attachment, admin.ModelAdmin)
admin.site.register(GenericAttachment, admin.ModelAdmin)
admin.site.register(Parent, ParentAdmin)

Attachments

Change History

04/09/09 10:18:53 changed by rutt

  • needs_better_patch changed.
  • component changed from Uncategorized to django.contrib.admin.
  • needs_tests changed.
  • needs_docs changed.

04/09/09 10:30:55 changed by rutt

See also #10770

04/10/09 05:07:32 changed by mrts

  • status changed from new to closed.
  • resolution set to duplicate.

Duplicate of #9493 .


Add/Change #10769 (IntegrityError with generic relations, unique_together, and inline admin forms)




Change Properties
Action