python - Django admin, filter objects by ManyToMany reference -


The simple photo gallery, photos, and gallery objects for the photogood app, the demo is implemented. There are several fields in the gallery object, which references the photo objects.

I should be able to get the list of all the photos for the given gallery. Is it possible to add the gallery filter to the admin's admin page? If this is possible, how to do it best?

You must type a custom filter speaker!
This will look like this:

  , F, request, params, model, model_admin): self Lookup_quoragg = f.name self._lookup_model = f.rel.to self.lookup_val = request.GET.get (self.lookup_kwarg, none) for self.user = request.user self.lookup_choices = G for gallery [( GPK, G. Names). Object.All ()] DEF Headout Out (Self): Return Lane (Self-Lookup_coreis) & gt; 1 DR title (self): Returns self_ lookup_model._meta.verbose_name FilterSpec.filter_specs.insert (0, (Lambda F: F.L.L.to == Gallery, GalleryFilterSpeak))  

Place this in a module in your app package in filters.py and import it into admin.py (it is important to import this so that the filter gets registered on the administrator Site!)

Edit: The "f" field is the example, in this case models.ManyToManyField the last line FilterSpec for all fields The Njikrit, whose gallery on the model. This will not work as you have mentioned that if the field is defined on the gallery model, because django.contrib.admin.views.main.ChangeList.get_filters checks if you defined in the list The field actually exists in the model (either does not work for related_name) I think the easiest way is that you can create a custom template for that changelist and filter your filter there. Iltr Spiisi itself does not need to be filtered, Dijengo use that URL only parameter for it!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -