models.py
class ChatMessage(models.Model): ip=models.IPAddressField() message=models.CharField(max_length=200) class BlockIp(models.Model): ip=models.IPAddressField()
admin.py
class ChatMessageAdmin(admin.ModelAdmin): def queryset(self, request): qs = super(ChatMessageAdmin, self).queryset(request)
I rewrote the queryset method for the ChatMessage class. I am trying to return something like:
SELECT * FROM chatmessage as v1 JOIN blockip as v2 on v1.ip!=v2.ip
so that the user sees only messages that have ip, which is not in the block record.
return qs.exclude(ip=BlockIp.objects.all().ip) does not match the syntax: (
Any tips?
source share