Model form will not display in the URL assigned

8 views
Skip to first unread message

Kean

unread,
Aug 14, 2019, 1:38:27 PM8/14/19
to Django users
Hi, 

New to Django, I'm trying to create a form which means user can update in the browser and it gets stored in the database, however my form wont appear in the browser.

please see setup:

URLS.py

path('Business register/Business management/Admin/Add new business', views.addnewbusiness, name='addnewbusiness'),

MODELS

class Businessownercreate(models.Model):
Creator = models.CharField(max_length=20)
Micro_Small_Medium = models.CharField(max_length=6)
Business_Name = models.CharField(max_length=20)
Owner_Firstname = models.CharField(max_length=20)
Owner_Surname = models.CharField(max_length=20)
Companies_House_Number = models.CharField(max_length=8)
Address_Line_1 = models.CharField(max_length=30)
Address_Line_2 = models.CharField(max_length=30)
Town = models.CharField(max_length=20)
City = models.CharField(max_length=20)
County = models.CharField(max_length=20)
Postcode = models.CharField(max_length=10)
Email = models.EmailField(max_length=50)
Phone = models.CharField(max_length=15)
Mobile = models.CharField(max_length=15)
Created_date = models.DateTimeField('date published')

def __unicode__(self):
return self.Business_Name

def __str__(self):
return self.Companies_House_Number
return self.Business_name

 FORMS.py

class Businessownercreate(forms.ModelForm):

class Meta:
model = Businessownercreate
fields = ["Creator", "Micro_Small_Medium", "Business_Name", "Owner_Firstname", 
"Owner_Surname", "Companies_House_Number", "Address_Line_1", "Address_Line_2",
"Town", "City", "County", "Postcode", "Email", "Phone", "Mobile", "Created_date"
]

VIEWS.py

def addnewbusiness(request):
if request == "POST":
form = Businessownercreate(request.POST)
if form.is_valid():
form.save()

return HttpResponseRedirect('/Business register/Business management/Admin/Add new business/business overview')
else:
form = Businessownercreate()

return render(request, 'businessownercreate.html')


TEMPLATES.

{% load static %}

    <!-- Compiled and minified CSS -->

    <!-- Compiled and minified JavaScript -->

<nav>
<div class="nav-wrapper">
<a href="/" class="brand-logo">Billntrade</a>
<ul id="nav-mobile" class="right hide-on-med-and down">
            <li><a href="/Business register/Business management/Admin/Add new business/Business overview">business overview</a></li>
<li><a href="/Business register/Business management/Admin/Add new business/Back">Back</a></li>
            <li><a href="/Business register/Business management/Admin/Add new business/account">{{user.username}}</a></li>
  </a></li>
</ul>
</div>
</nav>


<div class="container">
    <br>

        <form action="/Business register/Business management/Admin/Add new business" method="POST">
        {% csrf_token %}
             {{form.as_p}}  
                          

        <button class="btn" type = "submit">create</button>    
    </form>

Please can anyone help, I can't seem to get anything other than the button to appear?

Best,

K


Jonathan Villavicencio

unread,
Aug 14, 2019, 8:00:04 PM8/14/19
to django...@googlegroups.com

Hello!, change the " of the fields of the Meta class to ' in the class Busines..(forms.ModelForm)

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b9b7ce1-1161-439d-b485-516b89cb7ee0%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages