Reputation: 6754
I have a model with GenericForeignKey:
class Breadcrumbs( models.Model ):
title = models.CharField( max_length = 256 )
limit = models.Q( app_label = 'news', model = 'NewsPost' )
content_type = models.ForeignKey( ContentType, limit_choices_to = limit )
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey( 'content_type', 'object_id' )
class Meta:
db_table = 'breadcrumbs'
By default there is an input text widget for object_id:
How to make it as select with options? Also I would like to fill it with NewsPost ids (or with unicode() of NewsPost) by default.
Upvotes: 0
Views: 85
Reputation: 55207
You shouldn't use a PositiveIntegerField
here. You should use a ForeignKey
to NewsPost
.
This will do the two things you need with no additional effort.
Upvotes: 2