Hi Matthew and Joel. Thanks for your help.

I'm attaching the models.py, views.py and templates for your reference.  
I'm drawing a blank on the implementation that could trigger a delete.

Thanks again

On Tuesday, October 23, 2018 at 11:54:17 AM UTC-5, Matthew Pava wrote:
>
> And make sure your form is posting to the save view and not the delete 
> view.  Maybe show us your template.
>
>  
>
> *From:* django...@googlegroups.com <javascript:> [mailto:
> django...@googlegroups.com <javascript:>] *On Behalf Of *Joel
> *Sent:* Tuesday, October 23, 2018 11:32 AM
> *To:* django...@googlegroups.com <javascript:>
> *Subject:* Re: Django auto-deletes field related to MySQL Transactions
>
>  
>
> You could have a signal which captures all these and logs its origin.
>
>  
>
> On Tue, 23 Oct, 2018, 9:35 PM RyanW, <rwhit...@gmail.com <javascript:>> 
> wrote:
>
> Yes, I honestly don't see how Django could be doing this either.  The only 
> I could think of was user deletion, but no one has claimed to have done so.
>
>  
>
> No other apps are connected.
>
>  
>
> Thanks for the tip!!
>
>
> On Tuesday, October 23, 2018 at 10:05:51 AM UTC-5, Matthew Pava wrote:
>
> It doesn’t seem like Django would be doing this.
>
> Do you have any other apps connected to the database?
>
> You’ll probably want to surround your URL in quotation marks.  <a href=”{% 
> url ‘epedelete’ epe.id %}”>
>
>  
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *RyanW
> *Sent:* Tuesday, October 23, 2018 9:33 AM
> *To:* Django users
> *Subject:* Re: Django auto-deletes field related to MySQL Transactions
>
>  
>
> I have a button to delete a record by the user, displayed inside a 
> template as:
>
>  
>
> <td><a href={% url 'epedelete' epe.id %}><input class="btn btn-danger" 
> type="button" value="Delete" /></a></td>
>
>
> and the function in views.py
>
>  
>
> def delete(request, part_id=None):
>
>     obj = epe.objects.get(id=part_id)
>
>     obj.delete()
>
>     return HttpResponseRedirect(reverse('epe_home'))
>
>
> Other than that, I have some ForeignKey restraints on_delete to preserve 
> integrity, like so:
>
>     epe_ani2 = models.ForeignKey(
>
>         Subjects,
>
>         on_delete=models.PROTECT,
>
>         null=True,
>
>         blank=True
>
>     )
>
>
> As for the authentication backend, I'm using the default provided by 
> Django:
>
> ['django.contrib.auth.backends.ModelBackend']
>
>  
>
> Thank you for the help!
>
>
> On Tuesday, October 23, 2018 at 9:16:24 AM UTC-5, Matthew Pava wrote:
>
> Check your source code for any delete commands.
>
> This might also be your authentication backend.  Which one are you using?
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *RyanW
> *Sent:* Monday, October 22, 2018 7:55 PM
> *To:* Django users
> *Subject:* Django auto-deletes field related to MySQL Transactions
>
>  
>
> I have a Django site I'm developing, which I've connected to a MySQL db.  
> I haven't deployed into production yet, as I'm still working on a couple of 
> things, however I leave the server running in development for initial data 
> entry. 
>
>  
>
> I've noticed that some of the records already inputted gets deleted, 
> seemingly randomly. I enabled logging on MySQL and found logs like the 
> following:
>
>  
>
> 6798 Connect
> rya...@cobb.eyes.uab.edu on downswebdb2
>
> 6798 Query
> SET NAMES utf8
>
> 6798 Query
> set autocommit=0
>
> 6798 Query
> set autocommit=1
>
> 6798 Query
> SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
>
> 6798 Query
> SELECT `Epe_epe`.`id`, `Epe_epe`.`epe_type`, `Epe_epe`.`epe_type2_id`, 
> `Epe_epe`.`epe_date`, `Epe_epe`.`epe_ani`, `Epe_epe`.`epe_ani2_id`, 
> `Epe_epe`.`epe_apn`, `Epe_epe`.`epe_apn2_id`, `Epe_epe`.`epe_weight`, 
> `Epe_epe`.`epe_drug_type1`, `Epe_epe`.`epe_drug1`, `Epe_epe`.`epe_dose1`, 
> `Epe_epe`.`epe_amount1`, `Epe_epe`.`epe_route1`, `Epe_epe`.`epe_time1`, 
> `Epe_epe`.`epe_drug_type2`, `Epe_epe`.`epe_drug2`, `Epe_epe`.`epe_dose2`, 
> `Epe_epe`.`epe_amount2`, `Epe_epe`.`epe_route2`, `Epe_epe`.`epe_time2`, 
> `Epe_epe`.`epe_drug_type3`, `Epe_epe`.`epe_drug3`, `Epe_epe`.`epe_dose3`, 
> `Epe_epe`.`epe_amount3`, `Epe_epe`.`epe_route3`, `Epe_epe`.`epe_time3`, 
> `Epe_epe`.`epe_drug_type4`, `Epe_epe`.`epe_drug4`, `Epe_epe`.`epe_dose4`, 
> `Epe_epe`.`epe_amount4`, `Epe_epe`.`epe_route4`, `Epe_epe`.`epe_time4`, 
> `Epe_epe`.`epe_drug_type5`, `Epe_epe`.`epe_drug5`, `Epe_epe`.`epe_dose5`, 
> `Epe_epe`.`epe_amount5`, `Epe_epe`.`epe_route5`, `Epe_epe`.`epe_time5`, 
> `Epe_epe`.`epe_drug_type6`, `Epe_epe`.`epe_drug6`, `Epe_epe`.`epe_dose6`, 
> `Epe_epe`.`epe_amount6`, `Epe_epe`.`epe_route6`, `Epe_epe`.`epe_time6`, 
> `Epe_epe`.`epe_iso_start`, `Epe_epe`.`epe_iso_end`, `Epe_epe`.`epe_o2_end`
> , `Epe_epe`.`epe_start1`, `Epe_epe`.`epe_start2`, `Epe_epe`.`epe_start3`, 
> `Epe_epe`.`epe_start4`, `Epe_epe`.`epe_start5`, `Epe_epe`.`epe_start6`, 
> `Epe_epe`.`epe_start7`, `Epe_epe`.`epe_start8`, `Epe_epe`.`epe_hr1`, 
> `Epe_epe`.`epe_hr2`, `Epe_epe`.`epe_hr3`, `Epe_epe`.`epe_hr4`, `Epe_epe`.
> `epe_hr5`, `Epe_epe`.`epe_hr6`, `Epe_epe`.`epe_hr7`, `Epe_epe`.`epe_hr8`, 
> `Epe_epe`.`epe_spo2_1`, `Epe_epe`.`epe_spo2_2`, `Epe_epe`.`epe_spo2_3`, 
> `Epe_epe`.`epe_spo2_4`, `Epe_epe`.`epe_spo2_5`, `Epe_epe`.`epe_spo2_6`, 
> `Epe_epe`.`epe_spo2_7`, `Epe_epe`.`epe_spo2_8`, `Epe_epe`.`epe_temp1`, 
> `Epe_epe`.`epe_temp2`, `Epe_epe`.`epe_temp3`, `Epe_epe`.`epe_temp4`, 
> `Epe_epe`.`epe_temp5`, `Epe_epe`.`epe_temp6`, `Epe_epe`.`epe_temp7`, 
> `Epe_epe`.`epe_temp8`, `Epe_epe`.`epe_etco2_1`, `Epe_epe`.`epe_etco2_2`, 
> `Epe_epe`.`epe_etco2_3`, `Epe_epe`.`epe_etco2_4`, `Epe_epe`.`epe_etco2_5`, 
> `Epe_epe`.`epe_etco2_6`, `Epe_epe`.`epe_etco2_7`, `Epe_epe`.`epe_etco2_8`, 
> `Epe_epe`.`epe_rr1`, `Epe_epe`.`epe_rr2`, `Epe_epe`.`epe_rr3`, `Epe_epe`.
> `epe_rr4`, `Epe_epe`.`epe_rr5`, `Epe_epe`.`epe_rr6`, `Epe_epe`.`epe_rr7`, 
> `Epe_epe`.`epe_rr8`, `Epe_epe`.`epe_comment` FROM `Epe_epe` WHERE 
> `Epe_epe`.`id` = 1508
>
> 6798 Query
> set autocommit=0
>
> 6798 Query
> DELETE FROM `Epe_epe` WHERE `Epe_epe`.`id` IN (1508)
>
> 6798 Query
> commit
>
> 6798 Query
> set autocommit=1
>
> 6798 Quit
>
> Where Epe_epe is from a model called Epe in my Django app. 
>
>
> As far as I know, no user is performing delete commands on these records, 
> so can I assume Django is performing these deletes in the background?  What 
> would a trigger possibly be for these deletes?
>
>  
>
> Thank you
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> To post to this group, send email to djang...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/91c6af18-cdf0-45f4-9f1c-e865c7128334%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/91c6af18-cdf0-45f4-9f1c-e865c7128334%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> To post to this group, send email to djang...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/0be635cb-6f54-451c-ae92-07b38841e6c6%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/0be635cb-6f54-451c-ae92-07b38841e6c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com <javascript:>.
> To post to this group, send email to djang...@googlegroups.com 
> <javascript:>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/59a2ed67-2e8a-4864-9495-7d8e1810c4ad%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/59a2ed67-2e8a-4864-9495-7d8e1810c4ad%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com <javascript:>.
> To post to this group, send email to djang...@googlegroups.com 
> <javascript:>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAA%3Diw__WFtVJ6-zT793z8y-ZOf%2BcmLjAbJ%2B-9NaOT9mHtq6R0A%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAA%3Diw__WFtVJ6-zT793z8y-ZOf%2BcmLjAbJ%2B-9NaOT9mHtq6R0A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ae1ce38-8148-46bc-8a65-99569aeef9bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic import TemplateView, ListView, DetailView
from django.views.generic.edit import CreateView, UpdateView
from .forms import EpeForm
from Subjects.models import Subjects
from django.urls import reverse
from django.db.models import Q
import logging

logger = logging.getLogger('')

from .models import epe

class EpeListView(ListView):
    model = epe
    template_name = 'epe_home.html'

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            return epe.objects.filter(Q(epe_ani__icontains=query) | Q(epe_ani2__ani_num__icontains=query) | Q(epe_type__icontains=query)).order_by('-epe_date')
        else:
            return epe.objects.all().order_by('-epe_date')

class EpeDetailView(DetailView):
    model = epe
    template_name = 'epe_detail.html'

class EpeCreateView(CreateView):
    model = epe
    template_name = 'epe_new.html'
    form_class = EpeForm

    def get_success_url(self):
        return reverse('epe_home')

class EpeUpdateView(UpdateView):
    model = epe
    template_name = 'epe_update.html'
    form_class = EpeForm

    #def get_success_url(self):
    #    return reverse('epe_home')

def delete(request, part_id=None):
    obj = epe.objects.get(id=part_id)
    obj.delete()
    logger.error('Someone deleted record: '+str(part_id))
    return HttpResponseRedirect(reverse('epe_home'))
from django.db import models
from django.urls import reverse
import datetime
from Subjects.models import Subjects
from Irb.models import Irb
from ExamType.models import ExamType


class epe(models.Model):
    DRUG_CHOICES = (
        ('PD', ("PRE-ANESTHETIC DRUGS")),
        ('AI', ("ANESTHETIC INDUCTION")),
        ('ANTI', ("ANTIBIOTICS")),
        ('ANAL', ("ANALGESICS")),
        ('RV', ("REVERSAL AGENT"))
    )
    DRUGS = (
        ('K', ("Ketamine")),
        ('D', ("Dexdomitor")),
        ('A', ("Antisedan"))
    )
    epe_type = models.CharField(max_length=200)
    epe_type2 = models.ForeignKey(
        ExamType, on_delete=models.PROTECT, null=True, blank=True)
    epe_date = models.DateField()
    epe_ani = models.CharField(max_length=200, blank=True, null=True)
    epe_ani2 = models.ForeignKey(
        Subjects,
        on_delete=models.PROTECT,
        null=True,
        blank=True
    )
    epe_apn = models.CharField(max_length=200, blank=True, null=True)
    epe_apn2 = models.ForeignKey(
        Irb, on_delete=models.PROTECT, null=True, blank=True)
    # epe_date_of_birth -> why? just pull from Subjects
    epe_weight = models.CharField(max_length=200, blank=True)

    epe_drug_type1 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300)
    epe_drug1 = models.CharField(choices=DRUGS, default='K', max_length=300)
    epe_dose1 = models.CharField(max_length=200, blank=True)
    epe_amount1 = models.CharField(max_length=200, blank=True)
    epe_route1 = models.CharField(max_length=200, blank=True)
    epe_time1 = models.TimeField(null=True, blank=True)

    epe_drug_type2 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300)
    epe_drug2 = models.CharField(choices=DRUGS, default='K', max_length=300)
    epe_dose2 = models.CharField(max_length=200, blank=True)
    epe_amount2 = models.CharField(max_length=200, blank=True)
    epe_route2 = models.CharField(max_length=200, blank=True)
    epe_time2 = models.TimeField(null=True, blank=True)

    epe_drug_type3 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300)
    epe_drug3 = models.CharField(choices=DRUGS, default='K', max_length=300)
    epe_dose3 = models.CharField(max_length=200, blank=True)
    epe_amount3 = models.CharField(max_length=200, blank=True)
    epe_route3 = models.CharField(max_length=200, blank=True)
    epe_time3 = models.TimeField(null=True, blank=True)

    epe_drug_type4 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300, blank=True)
    epe_drug4 = models.CharField(
        choices=DRUGS, default='K', max_length=300, blank=True)
    epe_dose4 = models.CharField(max_length=200, blank=True)
    epe_amount4 = models.CharField(max_length=200, blank=True)
    epe_route4 = models.CharField(max_length=200, blank=True)
    epe_time4 = models.TimeField(null=True, blank=True)

    epe_drug_type5 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300, blank=True)
    epe_drug5 = models.CharField(
        choices=DRUGS, default='K', max_length=300, blank=True)
    epe_dose5 = models.CharField(max_length=200, blank=True)
    epe_amount5 = models.CharField(max_length=200, blank=True)
    epe_route5 = models.CharField(max_length=200, blank=True)

    epe_time5 = models.TimeField(null=True, blank=True)

    epe_drug_type6 = models.CharField(
        choices=DRUG_CHOICES, default='PD', max_length=300, blank=True)
    epe_drug6 = models.CharField(
        choices=DRUGS, default='K', max_length=300, blank=True)
    epe_dose6 = models.CharField(max_length=200, blank=True)
    epe_amount6 = models.CharField(max_length=200, blank=True)
    epe_route6 = models.CharField(max_length=200, blank=True)

    epe_time6 = models.TimeField(null=True, blank=True)

    epe_iso_start = models.TimeField(null=True, blank=True)
    epe_iso_end = models.TimeField(null=True, blank=True)
    epe_o2_end = models.TimeField(null=True, blank=True)

    epe_start1 = models.TimeField(null=True, blank=True)
    epe_start2 = models.TimeField(null=True, blank=True)
    epe_start3 = models.TimeField(null=True, blank=True)
    epe_start4 = models.TimeField(null=True, blank=True)
    epe_start5 = models.TimeField(null=True, blank=True)
    epe_start6 = models.TimeField(null=True, blank=True)
    epe_start7 = models.TimeField(null=True, blank=True)
    epe_start8 = models.TimeField(null=True, blank=True)

    epe_hr1 = models.CharField(max_length=200, blank=True)
    epe_hr2 = models.CharField(max_length=200, blank=True)
    epe_hr3 = models.CharField(max_length=200, blank=True)
    epe_hr4 = models.CharField(max_length=200, blank=True)
    epe_hr5 = models.CharField(max_length=200, blank=True)
    epe_hr6 = models.CharField(max_length=200, blank=True)
    epe_hr7 = models.CharField(max_length=200, blank=True)
    epe_hr8 = models.CharField(max_length=200, blank=True)

    epe_spo2_1 = models.CharField(max_length=200, blank=True)
    epe_spo2_2 = models.CharField(max_length=200, blank=True)
    epe_spo2_3 = models.CharField(max_length=200, blank=True)
    epe_spo2_4 = models.CharField(max_length=200, blank=True)
    epe_spo2_5 = models.CharField(max_length=200, blank=True)
    epe_spo2_6 = models.CharField(max_length=200, blank=True)
    epe_spo2_7 = models.CharField(max_length=200, blank=True)
    epe_spo2_8 = models.CharField(max_length=200, blank=True)

    epe_temp1 = models.CharField(max_length=200, blank=True)
    epe_temp2 = models.CharField(max_length=200, blank=True)
    epe_temp3 = models.CharField(max_length=200, blank=True)
    epe_temp4 = models.CharField(max_length=200, blank=True)
    epe_temp5 = models.CharField(max_length=200, blank=True)
    epe_temp6 = models.CharField(max_length=200, blank=True)
    epe_temp7 = models.CharField(max_length=200, blank=True)
    epe_temp8 = models.CharField(max_length=200, blank=True)

    epe_etco2_1 = models.CharField(max_length=200, blank=True)
    epe_etco2_2 = models.CharField(max_length=200, blank=True)
    epe_etco2_3 = models.CharField(max_length=200, blank=True)
    epe_etco2_4 = models.CharField(max_length=200, blank=True)
    epe_etco2_5 = models.CharField(max_length=200, blank=True)
    epe_etco2_6 = models.CharField(max_length=200, blank=True)
    epe_etco2_7 = models.CharField(max_length=200, blank=True)
    epe_etco2_8 = models.CharField(max_length=200, blank=True)

    epe_rr1 = models.CharField(max_length=200, blank=True)
    epe_rr2 = models.CharField(max_length=200, blank=True)
    epe_rr3 = models.CharField(max_length=200, blank=True)
    epe_rr4 = models.CharField(max_length=200, blank=True)
    epe_rr5 = models.CharField(max_length=200, blank=True)
    epe_rr6 = models.CharField(max_length=200, blank=True)
    epe_rr7 = models.CharField(max_length=200, blank=True)
    epe_rr8 = models.CharField(max_length=200, blank=True)

    epe_comment = models.TextField(blank=True)

    def get_absolute_url(self):
        return reverse('epe_detail', args=[str(self.id)])

    def __str__(self):
        return self.epe_type
from django.urls import path
from django.conf.urls import url

from . import views

urlpatterns = [
    path('', views.EpeListView.as_view(), name='epe_home'),
    path('new', views.EpeCreateView.as_view(), name='epe_new'),
    path('<int:pk>', views.EpeDetailView.as_view(), name='epe_detail'),
    path('<int:pk>/update', views.EpeUpdateView.as_view(), name='epe_update'),
    url(r'^(?P<part_id>[0-9]+)/epe_delete/$', views.delete, name='epedelete')
]

<<< text/html; charset=US-ASCII; name=epe_update.html: Unrecognized >>>

<<< text/html; charset=US-ASCII; name=epe_new.html: Unrecognized >>>

Reply via email to