Hola estoy arrancando a programar en Django. Venia bien hasta que me trabe con el tema de los formularios. Lo que quiero hacer es un formulario para insertar request de acceso a la base de datos, para que después sean procesadas. Aca abajo les pego mis lineas de código y mi resultado que no es el deseado ojala me puedan ayudar.
Views.py
from django.shortcuts import render
from django.views.generic import CreateView
from apps.crudRequestAccess.models import RequestUser
from apps.crudRequestAccess.forms import RequestAccessForm
# Create your views here.
class RequestCreate(CreateView):
model = RequestUser()
form_class = RequestAccessForm
template_name = 'crudRequestAccess/request_form.html'
request_form.py
{% extends "base/base.html" %}
{% block content %}
<div class="row">
<div class="col-md-8 col-sm-12">
{% block main-content %}
<form method="post">{% csrf_token %}
{{ form }}
<button class="btn btn-success" type="submit">Save</button>
<a class="btn btn-primary" href="#">Cancel</a>
</form>
{% endblock %}
</div>
<div class="col-md-4 hidden-sm">
{% block sidebar %}{% endblock %}
</div>
</div>
{% endblock %}
Forms.py
from django.forms import ModelForm
from django import forms
from apps.crudRequestAccess.models import RequestUser
class RequestAccessForm(forms.ModelForm):
class Meta:
model = RequestUser
fields = "__all__"
labels = {
'First_Name': 'First Name',
'Last_Name': 'Last Name',
'Enterprise_Id': 'EnterpriseId',
'Email': 'Email',
'Profile': 'Profile',
'Environment': 'Environment',
'Approved_By': 'Approved By',
'Roll_Off': 'Roll Off Date:',
'Public_Group': 'Public Group',
'Permission_Set_Licence': 'Permission Set Licence',
'Permissions_Set': 'Permissions Set',
'Comments': 'Comments',
'Status': 'Status',
'Rejected_By': 'Rejected By',
'Create_Date': 'Create Date',
'Create_By': 'Create By',
'Last_Modify': 'Last Modify',
'Last_Modify_By': 'Last Modify By'
}
widgets = {
'First_Name': forms.TextInput(attrs={'class': 'form-control'}),
'Last_Name': forms.TextInput(attrs={'class': 'form-control'}),
'Enterprise_Id': forms.TextInput(attrs={'class': 'form-control'}),
'Email': forms.TextInput(attrs={'class': 'form-control'}),
'Profile': forms.TextInput(attrs={'class': 'form-control'}),
'Environment': forms.Select(attrs={'class': 'form-control'}),
'Approved_By': forms.TextInput(attrs={'class': 'form-control'}),
'Roll_Off': forms.TextInput(attrs={'class': 'form-control'}),
'Public_Group': forms.TextInput(attrs={'class': 'form-control'}),
'Permission_Set_Licence': forms.TextInput(attrs={'class': 'form-control'}),
'Permissions_Set': forms.TextInput(attrs={'class': 'form-control'}),
'Comments': forms.TextInput(attrs={'class': 'form-control'}),
'Status': forms.TextInput(attrs={'class': 'form-control'}),
'Rejected_By': forms.TextInput(attrs={'class': 'form-control'}),
'Create_Date': forms.TextInput(attrs={'class': 'form-control'}),
'Create_By': forms.TextInput(attrs={'class': 'form-control'}),
'Last_Modify': forms.TextInput(attrs={'class': 'form-control'}),
'Last_Modify_By': forms.TextInput(attrs={'class': 'form-control'})
}
Models.py
from django.db import models
class RequestUser(models.Model):
First_Name = models.TextField(max_length=15),
Last_Name = models.TextField(max_length=15),
Enterprise_Id = models.CharField(max_length=50),
Email = models.EmailField(max_length=75),
Profile = models.TextField(max_length=50),
Environment = models.CharField(max_length=50),
Approved_By = models.CharField(max_length=50),
Roll_Off = models.DateField(),
Public_Group = models.CharField(max_length=5, default='None'),
Permission_Set_Licence = models.TextField(max_length=100),
Permissions_Set = models.TextField(max_length=100),
Comments = models.CharField(max_length=100),
Status = models.CharField(max_length=15, default="New", editable=False),
Rejected_By = models.CharField(max_length=15, editable=False, blank=True),
Create_Date = models.DateTimeField(auto_now_add=True, blank=False, editable=False),
Create_By = models.TextField(max_length=50),
Last_Modify = models.DateTimeField(auto_now=True, blank=True, editable=False),
Last_Modify_By = models.CharField(max_length=15, editable=False, blank=True)
class PublicGroup(models.Model):
Id = models.CharField(max_length=50, editable=False),
GroupName = models.CharField(max_length=50, editable=False),
GroupsAssociated = models.CharField(max_length=50, editable=False)
class Profile(models.Model):
Id = models.CharField(max_length=50, editable=False),
ProfileName = models.CharField(max_length=50, editable=False),
IdProfile = models.CharField(max_length=50, editable=False)
class PermissionsSet(models.Model):
Id = models.CharField(max_length=50, editable=False),
Name = models.CharField(max_length=50, editable=False)
class PermissionSetLicence(models.Model):
Id = models.CharField(max_length=50, editable=False),
Name = models.CharField(max_length=50, editable=False)
class PermissionSetLicenceAssignment(models.Model):
Id = models.CharField(max_length=50, editable=False),
Id_User = models.CharField(max_length=50, editable=False),
Name = models.CharField(max_length=50, editable=False)
class PermissionSetAssignment(models.Model):
Id = models.CharField(max_length=50, editable=False),
Id_User = models.CharField(max_length=50, editable=False),
Name = models.CharField(max_length=50, editable=False)
class Approve(models.Model):
#en lugar de poner uno individual poner el grupo del equipo
Enterprise_Id = models.CharField(max_length=50),
Team = models.CharField(max_length=50),
# Data Model Exception List
class ExceptionList(models.Model):
Enterprise_Id = models.CharField(max_length=50),
Profile = models.TextField(max_length=50),
Public_Group = models.CharField(max_length=5, default='None'),
Comments = models.TextField(max_length=200),
Approved_By = models.CharField(max_length=50)
# Data Model TestId
class TestId(models.Model):
First_Name = models.TextField(max_length=15),
Last_Name = models.TextField(max_length=15),
Enterprise_Id = models.CharField(max_length=50),
Email = models.EmailField(max_length=75),
Profile = models.TextField(max_length=50),
Public_Group = models.CharField(max_length=5, default='None'),
Permission_Set_Licence = models.TextField(max_length=100),
Permissions_Set = models.TextField(max_length=100),
# Users that SpringCM Team request for each integration
class SpringCM(models.Model):
First_Name = models.TextField(max_length=15),
Last_Name = models.TextField(max_length=15),
Enterprise_Id = models.CharField(max_length=50),
Email = models.EmailField(max_length=75),
Profile = models.TextField(max_length=50),
Public_Group = models.CharField(max_length=5, default='None'),
Permission_Set_Licence = models.TextField(max_length=100),
Permissions_Set = models.TextField(max_length=100),