Friday 15 June 2012

Preventing Django admin panel to show drop-down list in Inline display of ManyToMany relationships -


After

I can see a self referred model in Django 1.5 as below:

  RELATIONSHIP_PARENT = 1 RELATIONSHIP_BLOCKED = 2 RELATIONSHIP_STATUSES = ((RELATIONSHIP_PARENT, 'Parent'), (RELATIONSHIP_BLOCKED, 'block')) class message (models.Model): content = models.CharField ( "content", MAX_LENGTH = 160, db_index = true) relationships = models.ManyToManyField ( 'self', through = 'Relationship', symmetric = false, related_name = 'related_to') class relationship (models.Model): parent_message = models.ForeignKey (message, Related_name = ' Parent_messages') child_message = models.ForeignKey (message, related_name = 'child_messages') Ga = models.IntegerField (base = RELATIONSHIP_STATUSES)   

I configured the Django admin I inline when personally show relationships Message panel is shown below: django.contrib import admin from demo.models import message, relation class Relationshi pInline (admin.TabularInline): model = relation extra = 0 fk_name = 'parent_message' class MessageAdmin (admin.ModelAdmin): inlines = (RelationshipInline,) admin.site.register (message, MessageAdmin) admin.site.register (Relationship)

I table In multi I intend to store messages from (with many parents-child connections), whenever I see the personal panel through the admin panel, I see something like this:

Enter image details here

As shown in the red circle, Django Manager Collects all the messages in the database and in the form of a drop-down list in the menu Displays not. I've read some ways to stop it and the closest that I've found, but when I try to insert raw_id_fields = ('parent_message',) under the RelationshipInline class, Not so

If someone can recommend me a link or resource or just show me how to stop showing every entry / message in the drop-down list, I greatly appreciate help. Thank you.

This should work.

  class Rileshnformset (Besinlainformset): def get_queryset (self): If not Hettrr (self, '_queryset'): criteria = {} # Your criteria here qs = super (RelationshipFormSet, self) filter (** criteria) self._queryset = qs returns Swk_kwoyset class relationship line (admin.TabularInline): model = relationship additional = 0 fk_name = 'parent_message' formset = RelationshipFormSet    

No comments:

Post a Comment