Hi so my question is simple enough I think. I've a form that at present allows me to select a host from a drop-down menu and then select commands to issue to that host. These are tied to a field called current-commands.
Which I can then submit but rather then edit those existing command-nodes (themselves tied to the beacons) it is instead creating a new command-node e.g. a new host and new command. Not updating the selected hosts current command/commands.
This is a problem, and is to an extent tied into another question I've got and will post about. As ideally I want a client system to connect, check the current-commands (so it knows what to do) then shift the current commands to previous commands (to let me see previous commands issued that have been received and executed). So there is a question about multi-value fields to be asked, rather then single item, fields. However as these are separate issues I've a separate question for that. But I need to be able to alter the command-nodes thanks.
Any and all help appreciated. So far everyone who has helped me with these issues has been great. So thank you for any help you can offer.
views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import beacon
from .models import command_node
from .forms import Command_Form
from django.http import HttpResponseRedirect
def home(request):
form = Command_Form()
if request.method == "POST":
form = Command_Form(request.POST)
if form.is_valid():
form.save()
return render(request, 'home.html', {"form": form})
return render(request, 'home.html', {"form": form},)
models.py
from tkinter import CASCADE
from turtle import update
from django.db import models
class beacon(models.Model):
host_id = models.BigAutoField('Id', primary_key=True)
hostname = models.CharField('Hostname', max_length=200)
internalIp = models.CharField('Internal-IP', max_length=200)
externalIp = models.CharField('External-IP', max_length=200)
current_user = models.CharField('Current_User', max_length=200)
os = models.CharField('OS', max_length=200)
admin = models.CharField('Admin', max_length=200)
def __str__(self):
return self.hostname
CHOICES = [
('Sleep', "Sleep"),
('Open SSH_Tunnel', 'Open SSH_Tunnel'),
('Close SSH_Tunnel', 'Close SSH_Tunnel'),
('Open TCP_Tunnel', 'Open TCP_Tunnel'),
('Close TCP_Tunnel', 'Close TCP_Tunnel'),
('Open Dynamic', 'Open Dynamic'),
('Close Dynamic', 'Close Dynamic'),
('Task', 'Task'),
]
class command_node(models.Model):
host_id = models.ForeignKey(beacon, on_delete=models.CASCADE)
current_commands = models.CharField(choices=CHOICES, max_length=50, null=True)
previous_commands = models.CharField('previous_commands', max_length=2000, null=True)
def __str__(self):
return str(self.host_id)