클론코딩

    [pinterest clone (33)] MultipleObjectMixin을 통한 Projectapp 구현

    articleapp의 model을 보면 writer만 있는데 어떤 project(게시판)의 글인지도 추가 from django.contrib.auth.models import User from django.db import models # Create your models here. from projectapp.models import Project class Article(models.Model): writer = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='arrticle', null=True) project = models.ForeignKey(Project, on_delete=models.SET_NULL, related_name..

    [pinterest clone (32)] Projectapp 구현

    1. Create / Detail / List View (Update / delete) 2. Success_url to related Project 3. Login_required to CreateView 4. Model : title / description / image / created_at 개발 순서는 MVT 순서로 습관을 들이자. (setting 과 url 설정) 1 projectapp 시작 2 settings.py 3 urls.py 4 projectapp/urls.py 생성 : app_name 지정, view 만들고 라우팅할 urlpattern form app_name = 'projectapp' urlpatterns = [ ] (M: model) 5 models.py : title / desc..

    [pinterest clone (27)] articleapp 구현

    1 models.py from django.contrib.auth.models import User from django.db import models # Create your models here. class Article(models.Model): writer = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='arrticle', null=True) title = models.CharField(max_length=200, null=True) image = models.ImageField(upload_to='article/', null=False) content = models.TextField(null=True) created_at ..

    [pinterest clone (26)] Articleapp 화면구성 (MagicGrid)

    MagicGrid를 이용해 화면을 구성한다. github.com/e-oj/Magic-Grid e-oj/Magic-Grid A simple, lightweight Javascript library for dynamic grid layouts. - e-oj/Magic-Grid github.com 1 python manage.py startapp articleapp 2 settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ..

    [pinterest clone (23)] profileapp create view

    views.py 1 createview 만들기 class ProfileCreateView(CreateView): model = Profile context_object_name = 'target_profile' form_class = ProfileCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'profileapp/create.html' 2 profileapp/templates/profileapp/createview 만들기 {% extends 'base.html'%} {% load bootstrap4 %} {% block content %} Profile Create {% csrf_token %} {% bo..

    [pinterest clone (22)] ModelForm

    Profileapp을 만들기 시작한다. Account와 Profile을 1:1 로 매칭. 1개의 account는 1개의 profile을 가진다. 구성: Profile Image Profile Nickname Profile Message Delete View는 만들지 않을것이고, Detail View도 profile을 따로 보여주는 페이지를 안만들거니까 구현하지 않는다. 1 python manage.py startapp profileapp 2 settings.py에 추가 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.c..

    [pinterest clone (21)] superuser, media 관련설정

    superuser 생성 : python manage.py createsuperuser media 설정 account app 다음으로 profile app을 만들건데 이미지도 넣을 거기 때문에 이미지 필드를 모델에 설정해줄거다. settings.py에 URL 설정 추가 MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL 설정은 : 127.0.0.1:8000/media/test.jpg 이런걸 바라고 하는거고 MEDIA_ROOT는 : 파일을 올리게되면 platypus에서 media라는 디렉토리가 새로생기면서 올린파일들이 다 저장된다. 장고에서 이미지를 관리할때 쓰는 라이브러리: pillow 설치: pip install pil..

    [pinterest clone (20)] Authentication

    views.py - def hello_world def hello_world(request): if request.user.is_authenticated: if request.method == "POST": temp = request.POST.get('hello_world_input') new_hello_world = HelloWorld() new_hello_world.text = temp new_hello_world.save() return HttpResponseRedirect(reverse('accountapp:hello_world')) else: hello_world_list = HelloWorld.objects.all() return render(request, 'accountapp/hello_w..

    [pinterest clone (19)] Bug fix

    views.py class AccountCreateView(CreateView): model = User form_class = UserCreationForm success_url = reverse_lazy('accountapp:hello_world') template_name = 'accountapp/create.html' class AccountDetailView(DetailView): model = User context_object_name = 'target_user' template_name = 'accountapp/detail.html' class AccountUpdateView(UpdateView): model = User context_object_name = 'target_user' fo..

    [pinterest clone (18)] DeleteView를 이용한 회원탈퇴 구현

    views.py class AccountDeleteView(DeleteView): model = User success_url = reverse_lazy('accountapp:login') template_name = 'accountapp/delete.html' urls.py from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from accountapp.views import hello_world, AccountCreateView, AccountDetailView, AccountUpdateView, AccountDeleteView app_name = 'accountapp' urlpatterns =..