from django.contrib import admin
from member.models import Member
from catalogue.models import Post
from django import forms
from itertools import chain

class MemberAdmin(admin.ModelAdmin):
	def formfield_for_manytomany(self, db_field, request, **kwargs):
		if db_field.name == "books":
			self_pub_id = request.resolver_match.args[0]
			query1 = Post.objects.filter(memberid=None)
			query2 = Post.objects.filter(memberid=self_pub_id)
			kwargs["queryset"] =query2 | query1
		return super(MemberAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
	search_fields = ('Name','id', 'RollNo',)
	list_display = ('Name','id', 'RollNo','EmailID', 'Fine','Slots',)
	filter_horizontal = ('books',)
admin.site.register(Member,MemberAdmin)

# Register your models here.

@@ -281,16 +281,25 @@
 books%22:%0A
+%09%09%09try:%0A%09
 %09%09%09self_
@@ -338,16 +338,17 @@
 args%5B0%5D%0A
+%09
 %09%09%09query
@@ -389,16 +389,17 @@
 one)%0A%09%09%09
+%09
 query2 =
@@ -441,16 +441,17 @@
 pub_id)%0A
+%09
 %09%09%09kwarg
@@ -481,16 +481,117 @@
  query1%0A
+%09%09%09except IndexError:%0A%09%09%09%09query1 = Post.objects.filter(memberid=None)%0A%09%09%09%09kwargs%5B%22queryset%22%5D =query1%0A
 %09%09return

add member fixed