Hi, i'm using Django first time to actually make a web site.
I have coded model for user profiles and view for users to change
details in their profile.
When i log in, i can see that i'm logged in at front page and i can
use admin sites. But when i go to my view of changing user details, it
thinks that i'm not logged in. However, if i wipe out if-tags of
checking authentication, it retrieves information of my user profile
to my form.
# profile/models.py
#!/usr/bin/python
# -*- coding: latin-1 -*-
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm
# Create your models here.
class Profiili(models.Model):
kayttajanimi = models.ForeignKey(User,
unique=True,verbose_name=u'Käyttäjänimi',editable=True)
puhnro = models.CharField
(max_length=20,verbose_name=u'Puhelinnumero')
ika = models.DateField(verbose_name=u'Ikä')
vapaasana = models.TextField(blank=True,verbose_name=u'Vapaa
sana',help_text=u'Tähän voit esittää pelitoivomuksia yms. Mainitse
myös jos koneesi virtalähde on yli 450W ja epäilet virrankulutuksesi
olevan yli 350w (lähinnä vain markkinoiden tehokkaimmat koneet vievät
yli 300w)')
h_etunimi = models.CharField
(blank=True,max_length=50,verbose_name=u'Huoltajan
etunimi',help_text=u'Jos olet alle 18-vuotias, täytä myös seuraavat
tiedot')
h_sukunimi = models.CharField
(blank=True,max_length=50,verbose_name=u'Huoltajan sukunimi')
h_puh = models.CharField
(max_length=20,null=True,blank=True,verbose_name=u'Huoltajan
puhelinnumero')
ip = models.IPAddressField(verbose_name=u'IP-
osoite',editable=False,blank=True,null=True)
def __unicode__(self):
return self.kayttajanimi.username
class Meta:
verbose_name_plural = "Profiilit"
verbose_name = "Profiili"
class ProfiiliFormi(ModelForm):
class Meta:
model = Profiili
# profile/views.py
#!/usr/bin/python
# -*- coding: latin-1 -*-
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from monarilan.profiili.models import Profiili,ProfiiliFormi
from django.forms.models import modelformset_factory
from django.http import HttpResponseRedirect
# Create your views here.
def index(request):
# Yeah, i tried to check that im authenticated at here also
afterwards. Result was that it knew i was authenticated, but result
was still same. So the problem is in template(?)
if not request.user.is_authenticated():
return HttpResponseRedirect('/')
else:
profiili = Profiili.objects.get(pk=request.user.pk)
UserForm = ProfiiliFormi(instance=profiili)
if request.method == 'POST':
formset = UserForm(request.POST, request.FILES)
if formset.is_valid():
formset.save()
else:
return render_to_response('profiili.htm', {'form': UserForm,})
# templates/profiili.htm
{% extends "index.htm" %}
{% block headtitle %}Profiili{% endblock %}
{% block content %}
{# Don't mind about that there isn't any form-tags :p #}
{{ form.as_p }}
{% endblock %}
If there's something missing, tell ofc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---