I've got a Model in Django. It features a Group and within the group are Cameras.
class Groups(models.Model): groupName = models.CharField(max_length=255) class Cameras(models.Model): group = models.ForeignKey(Groups) cameraID = models.IntegerField()
After I attempt to remove a Camera or group of cameras within the model.
camera = Cameras.objects.filter(cameraID=int(camID)) camera.delete()
It removes any camera by having an ID More than . But When I've got a camera ID of '0' It does not remove. Any ideas why this is.
camera = Cameras.objects.get(pk=camID) you already know without a doubt you've only got one object. After that you can
Additionally you have no need for all of the '' figures inside your code.
When you're using filter, you will get or multiple objects came back, unlike
get that will only return 1 object, or cause errors.
If you wish to remove every objects that is came back from the filter, you are able to iterate regarding this like so:
cameras = Cameras.objects.filter(cameraID=int(camID)) ## let's say this returns [<Camera:1>,<Camera:2>] for camera in cameras: camera.delete() ## this loop will delete each object in the query