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

  • Home
  • SEARCH
  • 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 8424181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:55:09+00:00 2026-06-10T03:55:09+00:00

I’m trying to extend the User model in Django using inheritance. Here’s my model:

  • 0

I’m trying to extend the User model in Django using inheritance. Here’s my model:

class Paciente (User):
    Carteira = models.CharField(max_length=50, 
        verbose_name="Num Carteira Plano Saude",unique=True)
    Convenio = models.ForeignKey(Operadora,'Descricao', related_name="convenio", 
        verbose_name="Convenio",unique=True)
    DDD = models.CharField(max_length=2, verbose_name="DDD")
    Telefone = models.CharField(max_length=10, verbose_name="Telefone")

And here’s my view:

def paciente_register(request):
    PacienteFormSet = modelformset_factory(Paciente)

    if request.method == 'POST':
        form = PacienteFormSet(request.POST or None, 
            request.FILES or None, queryset=Paciente.objects.none(), 
            initial=[{
                'is_staff': False,
                'is_active': True, 
                'is_superuser': False, 
                'date_joined': datetime.now(), 
                'last_login': datetime.now()
            }]
        ) #incluir
        if form.is_valid():
            instance = form.save(commit=False) #pre-salva o registro
            for logvalue in instance:  # repoe os valores 'hidden' de log
                logvalue.is_staff = False
                logvalue.is_active = True
                logvalue.is_superuser = False
                logvalue.date_joined = datetime.now()
                logvalue.last_login = datetime.now()
            for reform in instance:  # salva no banco
                reform.save()
        else:
            return HttpResponseRedirect('/erro/')
    else:
        form = PacienteFormSet(queryset=Paciente.objects.none(), 
            initial=[{
                'is_staff':False,
                'is_active': True,
                'is_superuser': False,
                'date_joined': datetime.now(),
                'last_login': datetime.now()
            }]
        ) #incluir
    return render_to_response('register.html', {'form': form,}, context_instance=RequestContext(request))

And, last but not least, my template:

<form enctype="multipart/form-data" method="POST" action="/paciente_register/" >{% csrf_token %}
{{ form.management_form }}
   {% for formy in form.forms %}
      {{ formy.username.label_tag}}:{{formy.username}}<br>
      {{ formy.password.label_tag}}:{{formy.password}}<br>
      {{ formy.Carteira.label_tag}}:{{formy.Carteira}}<br>
      {{ formy.Convenio.label_tag}}:{{formy.Convenio}}<br>
      {{ formy.DDD.label_tag}}:{{formy.DDD}}<br>
      {{ formy.Telefone.label_tag}}:{{formy.Telefone}}<br>
      {{formy.is_staff.as_hidden}}
      {{formy.is_active.as_hidden}}
      {{formy.is_superuser.as_hidden}} 
      {{formy.date_joined.as_hidden}}
      {{formy.last_login.as_hidden}}

    {% endfor %}   
    <input type="submit" name="submit" value="Salvar" />
</form>

The user is supposed to register himself, but he will only have access to edit some of the fields, because the others I am setting inside the view and in the template, I am hiding them.

But the thing is that my form is not validating. I did a lot of research, but just a few examples over the internet use inheritance to extend User model. And this ones, does not show how would be the view that makes the registration of the user inside the application.

Any help would be very appreciated! 🙂

  • 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-10T03:55:10+00:00Added an answer on June 10, 2026 at 3:55 am

    The problem was on the view, after all. I was forcing the fields “date_joined” and “last_login” to receive datetime.now() because I was following the Django admin template. Sadly, this wasn’t correct and everytime I tried to add a user, it was jumping to the error template, which means that the form wasn’t filled properly. The solution was to make those fields receive date.today() and now it works fine.

    I think this model inheritance is still not working very good (Python 2.7 and Django 1.3). When you use it in your models, be sure of what kind of field Django is creating inside your database, and this will save you a lot of trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.