Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:05:11+00:00 2026-05-21T09:05:11+00:00

I am using django and as I am pretty new I have some questions.

  • 0

I am using django and as I am pretty new I have some questions.

I have one model called Signatures and a ModelForm called SignatureForm in my models.py file:

class Signature(models.Model):

    sig = models.ForeignKey(Device)
    STATE = models.CharField(max_length=3, choices=STATE_CHOICES)
    interval = models.DecimalField(max_digits=3, decimal_places=2)
    verticies = models.CharField(max_length=150)

class SignatureForm(ModelForm):

    class Meta:
        model = Signature
        widgets = {
            'verticies': HiddenInput,
       }

To use it, I wrote the following function in views.py:

def SigEditor(request):
    # If the form has been sent:
    if request.method == 'POST':
        form = SignatureForm(request.POST)
        # If it is valid
        if form.is_valid():
            # Create a new Signature object.
            form.save()
            return render_to_response('eQL/sig/form_sent.html')
        else:
        return render_to_response('eQL/sig/try_again.html')
    else:
        form = SignatureForm()
    return render_to_response('eQL/sig/showImage.html',  {'form' : form})

However, I don’t want to save all the new signatures. I mean, if the user introduces a new signature of the device A and state B, I would like to check if I have some signature like that in my database, delete it and then save the new one so that I have only one signature saved for each device and state.

I have tried something like this before saving it but of course is not working:

q = Signature.objects.filter(sig = s, STATE = st)
if q.count != 0:
      q.delete()
      form.save()

can anyone help?? thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:05:12+00:00Added an answer on May 21, 2026 at 9:05 am

    If you really do want to delete, why not?

    Signature.objects.filter(sig=s, STATE=st).delete()
    

    If you only ever want one combination of those items, you could use get_or_create, and pass in the instance to your ModelForm.

    instance, created = Signature.objects.get_or_create(sig=s, STATE=st)
    form = SignatureForm(request.POST, instance=signature)
    # edit instance.
    

    Or put it in your form save logic:

    class SignatureForm(ModelForm):
        def save(self, *args, **kwargs):
            data = self.cleaned_data
            instance, created = Signature.objects.get_or_create(sig=data['sig'], STATE=data['state'])
            self.instance = instance
            super(SignatureForm, self).save(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I'm new to Django and have only been using sqlite3 as a database engine
So I am pretty new to both Django and Javascript (I am using JQuery)
I am new to django and I have I think a pretty fundamental question.
Brand new to django. We have a legacy django project using django 0.96x that
I'm pretty new to web development. Lately I have been making a site using
I`m using Django to send some emails with embedded images to my gmail account.
I am using django-registration and would like to have a different page for failed
I'm using Django's post_save signal to send emails to users whenever a new article
I'm using Django 1.4 with Python 2.7 on Ubuntu 12.04. I have a template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.