Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
AttributeError at / type object 'Form' has no attribute 'objects', how to fix?

AttributeError at / type object 'Form' has no attribute 'objects', I'm new to django, I'd appreciate a brief explanation

views.py


from django.shortcuts import render,redirect
from django.contrib import messages
from .forms import *


def main(request):
    if request.method == "POST":
        form = Form(request.POST)
        if form.is_valid():
            Form.objects.get_or_create(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                phone=form.cleaned_data['phone']
            )
            messages.success(request, 'Form has been submitted')
            return redirect('/')
        else:
            return HttpResponse("Invalid data")
    else:
        form = Form()
    return render(request, 'app/main.html', {'form': form})

models.py


class ModelsForm(models.Model):
    name = models.CharField(max_length=30)
    email = models.CharField(max_length=30)
    phone = models.CharField(max_length=30)

    objects = models.Manager()

forms.py

from .models import ModelsForm

class Form(ModelForm):
    class Meta:
        model = ModelsForm
        fields = '__all__'```
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are making things confusing: your model named ModelsForm which suggests that it is a form, not a model. If you thus want to obtain the objects you can work with:

ModelsForm.objects.get_or_create(
    name=form.cleaned_data['name'],
    email=form.cleaned_data['email'],
    phone=form.cleaned_data['phone']
)

But I strongly advise to rename your models to names that do not hint these are forms, views, admins, etc.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!