Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#7875 closed (worksforme)

Admin changelist not showing any rows when having multiple foreignkeys in model.

Reported by: luddep@… 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)

Picture 1.png (169.5 KB ) - added by luddep@… 16 years ago.
screenshot of problem

Download all attachments as: .zip

Change History (11)

by luddep@…, 16 years ago

Attachment: Picture 1.png added

screenshot of problem

comment:1 by Brian Rosner, 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 anonymous, 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 Jacob, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:4 by David Gouldin, 16 years ago

Resolution: worksforme
Status: newclosed

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 Ludwig Pettersson, 16 years ago

Resolution: worksforme
Status: closedreopened

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 Gary Wilson, 16 years ago

Resolution: worksforme
Status: reopenedclosed

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 Ludwig Pettersson, 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 Ludwig Pettersson, 16 years ago

Resolution: worksforme
Status: closedreopened

comment:9 by James Bennett, 16 years ago

Resolution: worksforme
Status: reopenedclosed

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.

comment:10 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top