1

I'm using a model and a form in django to collect some text information

class Longlist(models.Model):
    text_input = models.CharField(max_length=3000, default='First Last email')

    def __unicode__(self):
         return self.text_input

Once I've collected this information, I don't need to keep it. What is the best way to clear the instances from the model? I'm just learning django so I don't know if an ever increasing index matters or not.

Longlist.objects.all().delete()

Deletes the instances but I think the index always increases every time my form is submitted. I don't know if this is a problem, and I'm not sure I know how to retrieve Longlist.text_input if I don't know what the current id is. eg if the form has been submitted 43 times, I would need to know this so I could get my information from Longlist.text_input(id=42). I do want to run the view/form over and over though, so I thought it would be easiest if my view always looks for Longlist.text_input(id=0)

Perhaps this is a good solution but I'm not sure: django model: objects.all().delete() doesn't

Community
  • 1
  • 1
Doug Smith
  • 500
  • 7
  • 21
  • 1
    An increasing index would not be a problem, however if you don't need to keep the data, just don't save it in the first place. You can just pick the data from the form, and not worry about how many times the view has run before. – henrikstroem Aug 23 '15 at 10:00
  • Or, don't bother with a model at all, just use a standard form. – Daniel Roseman Aug 23 '15 at 10:12
  • That was my original idea. I tried a lot of searches but couldn't figure out how to get info from a standard form into a variable in my view. I want to parse the text using python methods. – Doug Smith Aug 23 '15 at 14:20

0 Answers0