#7875 closed (worksforme)
Admin changelist not showing any rows when having multiple foreignkeys in model.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | foreignkeys newforms-admin | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using two foreignkeys, such as:
class Comment(models.Model): author = models.CharField(max_length=140) body = models.TextField() post = models.ForeignKey(Post) parent = models.ForeignKey('self')
the admin changelist for that model doesn't show any rows:
http://dl.getdropbox.com/u/24582/Picture%201.png
Rows are only shown when I comment out one of the foreignkeys, doesn't matter which.
This only occurs when using two ForeignKeys in the same model.
I'm running the latest trunk (8031).
Attachments (1)
Change History (11)
by , 16 years ago
Attachment: | Picture 1.png added |
---|
comment:1 by , 16 years ago
milestone: | 1.0 alpha |
---|
Dont mark a milestone until it is verified. I have several models with multiple foreign keys and they work fine. Can you also share what your ModelAdmin looks like?
comment:2 by , 16 years ago
oh, whops! First time submitter - sorry.
class CommentAdmin(admin.ModelAdmin): ordering = ('-date',) list_display = ('author', 'body', 'date', 'note',) search_fields = ('author','body',) list_filter = ('spam','date','note',) admin.site.register(Comment, CommentAdmin)
comment:3 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I can't reproduce this bug with the model and admin classes provided. Can you provide a minimal example with data to illustrate the issue?
comment:5 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I found a solution a while ago but forgot to check back:
If I add either of the two foreignkeys ( Parent or Note ) to my list_display all the rows disappear from my admin.
Bad - no rows show:
list_display = ('author','body', 'date','note',)
Good - everything is fine:
list_display = ('author','body', 'date',)
If this doesn't help I guess it's something with my data - but it would be weird that with fix it would be my data.
comment:6 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | reopened → closed |
There is no "note" in the model example you provided, the only foreign keys are "post" and "parent". I was sitting next to David (dgouldin) when he tried with both "post" and "parent" in list_display and could not reproduce the problem. He also tried creating a circular reference with the parent fields, but still the rows displayed as they should.
Are you using the latest trunk revision? Please provide a minimal (and complete) model and list_display example that reproduces your problem. Until then, closing this as worksforme.
comment:7 by , 16 years ago
Ah, it seems that I changed note to post for clarification when I first submitted it.
Using the latest trunk (8423).
Complete models & model admin for comment where the rows are a no show as long as 'note' is in list_display:
class Note(models.Model): title = models.CharField(max_length=140) url = models.URLField(blank=True) slug = models.SlugField() body = models.TextField() tags = models.ManyToManyField(Tag) date = models.DateTimeField() published = models.BooleanField(default=True) internal = models.BooleanField() def __unicode__(self): return self.title class Meta: ordering = ["-date"] def get_absolute_url(self): return "/notebook/%s/%02d/%02d/%s/" % (self.date.year, self.date.month, self.date.day, self.slug) def comment_set_ham(self): return self.comment_set.filter(spam=False) def comment_set_ham_parents(self): return self.comment_set.filter(spam=False).filter(parent=None) class Comment(models.Model): author = models.CharField(max_length=140) email = models.EmailField() website = models.URLField(blank=True) body = models.TextField() date = models.DateTimeField() spam = models.BooleanField(default=False) ip = models.IPAddressField() note = models.ForeignKey(Note) parent = models.ForeignKey('self') def __unicode__(self): return self.body class Meta: ordering = ["date"] def comment_set_ham_children(self): return self.comment_set.all().filter(spam=False)
Full admin:
class CommentAdmin(admin.ModelAdmin): ordering = ('-date',) list_display = ('author','body', 'date','note',) search_fields = ('author','body',) list_filter = ('spam','date','note',) fieldsets = ( (None, { 'fields': ('author', 'email', 'website', 'body', 'date') }), ('Advanced options', { 'classes': ('collapse',), 'fields': ('ip','note','parent') }), )
comment:8 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
comment:9 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | reopened → closed |
Using almost the model and admin definitions above, I cannot reproduce this. However, I say "almost" because it's impossible to insert data into the Comment
model, as defined, since the foreign key to "self" is required but can't be filled in for the very first Comment
entered.
screenshot of problem