I would like not to display a field in form if I have a boolean field in database set to False.
Here is my code:
class CreateServer(ModelForm):
def __init__(self, g, *args, **kwargs):
super(CreateServer, self).__init__(*args, **kwargs)
if g.boolean_clients:
self.fields['clients'].queryset = Clients.objects.filter(game=g)
else:
# the fields['clients'] shouldn't be displayed in form
pass
...
class Meta:
model = Server
queryset = Server.objects.filter()
fields = ['hostname', 'clients', 'map']
So if g.boolean_clients is true, there must be the filter, but if g.boolean_clients is false I do not want to display this field in form.
Is there any way hot to do it?