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 8450787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:04:13+00:00 2026-06-10T11:04:13+00:00

I created two classes: Client (attributes: name and sex) and Account (attributes: customer[fk], the

  • 0

I created two classes: Client (attributes: name and sex) and Account (attributes: customer[fk], the payment status). I show the form from templates; When I click the link “Add Customer” it opens the form of creation, from what has in models.py, other words can only create a client to “name and sex,” but not I can integrate in the same form payment situation.

models.py

from django.db import models

class Cliente(models.Model):
    SEXO = (
        ('M', 'Masculino'),
        ('F','Feminino'),
    )

    nome = models.CharField("Nome do cliente", max_length=255)
    sexo = models.CharField("Sexo", max_length=1, choices=SEXO)

    def __unicode__(self):
        return self.nome

    class Meta:
        verbose_name = 'Cliente'
        verbose_name_plural = 'Clientes'

class Conta(models.Model):
    STATUS_CONTA = (
            ('A', 'A Pagar'),
            ('P', 'Pago'),
        )

    cliente = models.ForeignKey(Cliente, related_name='conta')
    situacao = models.CharField("Situação", max_length=50, choices=STATUS_CONTA)

    class Meta:
        verbose_name = 'Conta'
        verbose_name_plural = 'Contas'

    def __unicode__(self):
        return self.cliente.nome

forms.py

from django.forms.models import ModelForm
from cadastro.models import Cliente, Conta

__author__ = 'Admin'

class ClienteForm(ModelForm):
    class Meta:
        model = Cliente

index.html

<html>
<body>
<a href='/adicionar_cliente/'>Adicionar cliente</a>
    {% for cliente in clientes %}
        {% for conta in cliente.conta.all %}
            <p>Nome: {{cliente.nome}}</p>
            <p>Sexo: {{cliente.get_sexo_display}} </p>
            <p>Situação do pedido: {{conta.get_situacao_display}}</p>
        {% endfor %}
            <p><a href='/excluir/{{cliente.id}}/'>Excluir?</a></p>
            <p><a href='/editar/{{cliente.id}}/'>Editar</a></p>
            <hr>
    {% empty %}
            <h3>Não existe nenhum cliente.</h3>
    {% endfor %}
</body>
</html>

form.html

<html>
<body>
    <form action='/{{action}}/' method='post'>
        {% csrf_token %}
        <table>
            {{form}}
        </table>
        <input type='submit' value='Adicionar' />
    </form>
</body>
</html>
  • 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-06-10T11:04:14+00:00Added an answer on June 10, 2026 at 11:04 am

    You can create two forms to accomplish this task.

    forms.py

    ...
    class ClienteForm(ModelForm):
        class Meta:
            model = Cliente
    class ContaForm(ModelForm):
        class Meta:
            model = Conta
            exclude = ("cliente") #exclude the cliente field from showing up in the form rendering. 
    

    form.html

    <html>
    <body>
    <form action='/{{ action }}/' method='post'>
        {% csrf_token %}
        <table>
            {{ form.as_table }} <!-- added as table which was missing from original post. -->
            {{ form2.as_table }}
        </table>
        <input type='submit' value='Adicionar' />
    </form>
    </body>
    

    views.py

    ...
    def form(request):
        if request.method == 'POST':
            form = ClienteForm(request.POST)
            form2 = ContaForm(request.POST)
            if form.is_valid() and form2.is_valid():
                client = form.save()
                conta = form2.save(commit=False)
                conta.cliente = client
                contra.save()
        else:
            form = ClienteForm()
            form2 = ContaForm()
           return render_to_response('form.html', locals(), context_instance = RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created two classes in netbeans;One of them is a JPanel form and another
I've created two classes with methods with same name. In one of them it
I have created two viewController classes such that one is superclass of another.i have
Say I have two classes created work and workItem. CWorker *work = new CWorker();
I have two classes with many-to-many relation so I created a join table in-between
I have two model classes, say parent and child. Parents are created first, and
I created two dropdpwn calendar in my form with these codes: <script type=text/javascript src=http://code.jquery.com/jquery-latest.js></script>
I have two classes; one is a server, another one is a client, and
I've created two classes in business layer. the first one is called Users with
I created client from wsdl file using visual studio 2010 Pro, created new project,

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.