__models py class Profile models Model SEX_CHOICES Unknown unknown Fem

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
__models.py
class Profile(models.Model):
SEX_CHOICES = (
('Unknown', 'unknown'),
('Female', 'female'),
('Male', 'male'))
user = models.ForeignKey(User, unique=True)
timezone = models.CharField(max_length=50, default='Europe/London')
site = models.URLField(max_length=50, default='www.example.com')
sex = models.CharField(max_length=10, choices=SEX_CHOICES)
location = models.CharField(max_length=30)
def __unicode__(self):
return ("%s's profile") % self.user
__forms.py
class ProfForm(forms.ModelForm):
class Meta:
model = Profile
__views.py
@login_required
def profile1(request):
profile, created = Profile.objects.get_or_create(user=request.user)
if request.method == 'POST':
form = ProfForm(request.POST, instance=profile)
if form.is_valid():
form.save()
else:
form = ProfForm(instance=profile)
return render_to_response('sitereg/profile.html', {'form': form})
__profile.html
{% extends "base.html" %}
{% block title %} Профайл {% endblock %}
{% block content %}
<h1> Профайл </h1>
<form action='.' method="post">
<table>
<div class="wide">{{ form.as_table }} </div>
</table>
<p><input type="submit" value="Submit" /></p>
</form>
{% endblock %}