Code

Opened 6 years ago

Closed 6 years ago

#9062 closed (duplicate)

admin disallows saving Null fk to more than one object

Reported by: smcoll Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

from django.db import models
from django.contrib.auth.models import User

class Contact(models.Model):
    user = models.ForeignKey(User, unique=True, null=True, blank=True)

In the admin, you can't save more than one model with a Null (-------) fk because you get an error: "Contact with this User already exists."

So it's as if Django is treating the "no relation" selection as an FK itself, and since unique=True, no more than one model can have a Null fk.

In my understanding, the model above should allow for any number of Null relations, but only allow one relation per User instance.

Might possibly be related to #9039.

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Unless I am missing something, this is more than related to #9039, it is #9039. Admin uses ModelForms, so problems they exhibit will show up in Admin, and fixing it for ModelForms in general will fix it for Admin, so we don't need two open tickets tracking this.

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.