Petey
unread,Jul 17, 2011, 5:05:44 AM7/17/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hi
1. When in django.admin I want to pick a source from dropdown list it always lists every item as "source object".
How I can modify it so it will show source_name from Source model?
from django.contrib import admin
from news.models import News, Comment, Source
class NewsAdmin(admin.ModelAdmin):
date_hierarchy = 'date_added'
list_display = ('date_added', 'title', 'created_by')
list_display_links = ('date_added', 'title', 'created_by', )
fields = ['title', 'text', "source", 'created_by']
class SourceAdmin(admin.ModelAdmin):
list_display = ('source_name', 'source_url')
Models:
class News(models.Model):
source = models.ForeignKey("Source", related_name="source_name_set", blank=True, null=True)
class Source(models.Model):
source_name = models.CharField(max_length=50)
source_url = models.URLField("Link")
2. I am having a problem with fieldsets in django admin, second parameter "advanced options does not work for any subclass of models.
It always returns me an error: 'NewsAdmin.fieldsets[1][1]['fields']' refers to field 't' that is missing from the form.
where field "x" is always the first letter of particural model subclass for exmaple "s" - source, "t" title.
fieldsets = (
(None, {
'fields': ('text')
}),
('Advanced options', {
'classes': ('collapse',),
'fields': ('title')
}),
)
3. In list display in admin.model I'd like to view connected data (foreign key) from another model.
For example I have a CommentAdmin class and I want to see the title from NewsAdmin class and link it to particural news.
I have completely no idea how to do it - I couldn't find any examples in django docs
class CommentAdmin(admin.ModelAdmin):
date_hierarchy = 'date_added'
list_display = ('id', 'date_added', 'title', )
class NewsAdmin(admin.ModelAdmin):
date_hierarchy = 'date_added'
list_display = ('date_added', 'title', 'created_by')
list_display_links = ('date_added', 'title', 'created_by', )
fields = ['title', 'text', "source", 'created_by']
Please provide me some hints and help with these 3 issues and I will try to resolve the problems :)
I will appreciate it