Can I extend the admin form to my page?

Asked

Viewed 84 times

1

I have a form created and displayed with the admin the way I want...but it is a site to fill out user registration, so the user does not have access to admin, I want the admin form to be used outside of it.

In mine are not showing the option fields, for example that appear in the form inside the admin

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

        from __future__ import unicode_literals

from django.db import models
from django.db import models


VINCULO = (
    (u'1', u'Bolsista'),
    (u'2', u'Estagiário'),
    (u'3', u'Terceiro'),
    (u'4', u'Servidor'),
    (u'5', u'Aluno Pós-Graduação'),
    (u'6', u'Servidor de outros órgãos'),
    (u'7', u'Professor Colaborador'),
)

SALAS = (
    (u'1', u'SysAdmin'),
    (u'2', u'Help Desk'),
)

RENOVADO = (
    (u'1', u'Sim'),
    (u'2', u'Não'),
)

EMPRESAS = (
    (u'1', u'Cray'),
    (u'2', u'Outra'),
)

TIPO = (
    (u'1', u'Técnico'),
    (u'2', u'Tecnologista'),
)


class Inscricao(models.Model):
        vinculo = models.CharField(max_length=100, choices=VINCULO)
        registro = models.IntegerField()
        nome = models.CharField(max_length=100)
        email = models.EmailField(unique=True)
        data_nascimento = models.DateField()
        data_admissao = models.DateField()
        sala = models.CharField(max_length=100, choices=SALAS)
        telefone = models.CharField(max_length=30)
        ramal = models.CharField(max_length=30)
        orientador = models.CharField(max_length=100)
        data_fim_contrato = models.DateField()
        renovado = models.CharField(max_length=4, choices=RENOVADO)
        empresa_responsavel = models.CharField(max_length=50, choices=EMPRESAS)
        tipo = models.CharField(max_length=50, choices=TIPO)
        criado_em = models.DateTimeField('criado em', auto_now_add=True)

        class Meta:
                ordering = ['criado_em']
                verbose_name = (u'nome')
                verbose_name_plural = (u'nomes')

        def __unicode__(self):
                return self.nome
  • Post your code so it’s easier to make a suggestion!

  • I put picture, thanks for the suggestion

  • Admin, as the name suggests, was made for administrators and/or developers of the site, although many people use it for everything (bad practice). Forms for end users, you have to develop your own. Some packages like Crispy-Forms can help, see a [list here. [(https://djangopackages.org/grids/g/forms/). At the moment I am using the Django-material., If you want to preserve the original Django-Forms layout (without the material) opt for Crispy-Forms.

1 answer

0


By Django admin, only if the user has access.

If you want to create a form based on the characteristics of your models in a frontend, I suggest using the Django Forms.

Example:

Forms.py

from django import forms

class NameForm(forms.Form):
    your_name = forms.CharField(label='Your name', max_length=100)

html template.

<form action="/your-name/" method="post">
    {% csrf_token %}
    {{ form }}
    <input type="submit" value="Submit" />
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.