-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09060ef
commit 409034a
Showing
18 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ | |
|
||
LANGUAGE_CODE = 'zh-hans' | ||
|
||
TIME_ZONE = 'UTC' | ||
TIME_ZONE = 'Asia/Shanghai' | ||
|
||
USE_I18N = True | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
from django.contrib import admin | ||
from .models import * | ||
|
||
# Register your models here. | ||
class ProfileAdmin(admin.ModelAdmin): | ||
list_display = ('user','location','avatar') | ||
admin.site.register(Profile,ProfileAdmin) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 2.0.2 on 2018-02-24 09:02 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Profile', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('location', models.CharField(blank=True, max_length=30)), | ||
('avatar', models.ImageField(upload_to='avatar/')), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.0.2 on 2018-02-24 09:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('userpage', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='profile', | ||
name='avatar', | ||
field=models.ImageField(blank=True, null=True, upload_to='avatar/'), | ||
), | ||
] |
Binary file not shown.
Binary file added
BIN
+596 Bytes
userpage/migrations/__pycache__/0002_auto_20180224_1712.cpython-36.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from django.forms import ModelForm,Textarea | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
# Create your models here. | ||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(User, on_delete=models.CASCADE) | ||
#bio = models.TextField(max_length=500, blank=True) | ||
location = models.CharField(max_length=30, blank=True) | ||
#birth_date = models.DateField(null=True, blank=True) | ||
avatar = models.ImageField(upload_to='avatar/', blank=True, null=True) | ||
|
||
@receiver(post_save, sender=User) | ||
def create_user_profile(sender, instance, created, **kwargs): | ||
if created: | ||
Profile.objects.create(user=instance) | ||
|
||
@receiver(post_save, sender=User) | ||
def save_user_profile(sender, instance, **kwargs): | ||
instance.profile.save() | ||
|
||
class UserForm(ModelForm): | ||
class Meta: | ||
model = User | ||
fields = ('username', 'first_name', 'last_name', 'email') | ||
|
||
class ProfileForm(ModelForm): | ||
class Meta: | ||
model = Profile | ||
fields = ('location', 'avatar') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
{% if messages %} | ||
<ul class="messages"> | ||
{% for message in messages %} | ||
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
{{ user_form.as_p }} | ||
{{ profile_form.as_p }} | ||
<button type="submit">Save changes</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpResponse,HttpResponseRedirect | ||
from django.template import RequestContext,Template,Context,loader,defaultfilters | ||
from django.shortcuts import render_to_response | ||
from django.shortcuts import render_to_response,redirect | ||
from django.contrib.auth.decorators import login_required | ||
from django.db import transaction | ||
from .models import * | ||
from django.contrib import messages | ||
|
||
# Create your views here. | ||
|
||
def homepage(request, user_id): | ||
return HttpResponse("You're looking at user %s." % user_id) | ||
|
||
|
||
@login_required | ||
@transaction.atomic | ||
def update_profile(request): | ||
if request.method == 'POST': | ||
user_form = UserForm(request.POST, instance=request.user) | ||
profile_form = ProfileForm(request.POST, instance=request.user.profile) | ||
if user_form.is_valid() and profile_form.is_valid(): | ||
user_form.save() | ||
profile_form.save() | ||
messages.success(request, '用户资料更新成功!') | ||
return redirect('.') | ||
#return redirect('settings:profile') | ||
else: | ||
messages.error(request, 'Please correct the error below.') | ||
#messages.error(request, _('Please correct the error below.')) | ||
else: | ||
user_form = UserForm(instance=request.user) | ||
profile_form = ProfileForm(instance=request.user.profile) | ||
return render(request, 'userpage/profile.html', { | ||
'user_form': user_form, | ||
'profile_form': profile_form | ||
}) |