diff --git a/README.md b/README.md index 20fe7f3..54f78e7 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,11 @@ Clonning instagram with python django and react and react native - 이미지를 업로드 , 사용 할수 있도록 앱을 만들어줌 limstagram 폴더 및에 이미지폴더 생성됨 - 이후 base.py 에서 LOCAL_APPS 에 images 추가하기 - + python manage.py migrate python manage.py makemigrations (생성한 모델, 어플레키에션 필드들을 변경시) + python manage.py createsuperuser (장고 슈퍼유저 생성) + ## 알아야 할것들 > Django ORM @@ -64,6 +66,12 @@ fluffy.delete() ``` -> Class Ingeritance +> Class Ingeritance and Models and Fields + +- https://docs.djangoproject.com/en/1.11/topics/db/models/ +- https://docs.djangoproject.com/en/1.11/ref/models/fields/ + +> Abstract base classes -> Models and Fields +- https://docs.djangoproject.com/en/1.11/topics/db/models/#abstract-base-classes +- https://docs.djangoproject.com/en/1.11/ref/models/fields/ \ No newline at end of file diff --git a/limstagram/images/migrations/0001_initial.py b/limstagram/images/migrations/0001_initial.py new file mode 100644 index 0000000..66cc604 --- /dev/null +++ b/limstagram/images/migrations/0001_initial.py @@ -0,0 +1,40 @@ +# Generated by Django 2.0.7 on 2018-07-24 11:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Comment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateField(auto_now_add=True)), + ('updated_at', models.DateField(auto_now=True)), + ('message', models.TextField()), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Image', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateField(auto_now_add=True)), + ('updated_at', models.DateField(auto_now=True)), + ('file', models.ImageField(upload_to='')), + ('location', models.CharField(max_length=140)), + ('caption', models.TextField()), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/limstagram/images/models.py b/limstagram/images/models.py index 71a8362..95ff502 100644 --- a/limstagram/images/models.py +++ b/limstagram/images/models.py @@ -1,3 +1,19 @@ from django.db import models # Create your models here. +class TimeStampedModel(models.Model): + created_at = models.DateField(auto_now_add=True) + updated_at = models.DateField(auto_now=True) + + class Meta: + abstract = True + +class Image(TimeStampedModel): + file = models.ImageField() + location = models.CharField(max_length=140) + caption = models.TextField() + + +class Comment(TimeStampedModel): + message = models.TextField() + \ No newline at end of file diff --git a/limstagram/users/migrations/0002_auto_20180724_2012.py b/limstagram/users/migrations/0002_auto_20180724_2012.py new file mode 100644 index 0000000..9a30eb8 --- /dev/null +++ b/limstagram/users/migrations/0002_auto_20180724_2012.py @@ -0,0 +1,33 @@ +# Generated by Django 2.0.7 on 2018-07-24 11:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='bio', + field=models.TextField(null=True), + ), + migrations.AddField( + model_name='user', + name='gender', + field=models.CharField(choices=[('male', 'Male'), ('female', 'Female'), ('not-specified', 'Not specified')], max_length=80, null=True), + ), + migrations.AddField( + model_name='user', + name='phone', + field=models.CharField(max_length=140, null=True), + ), + migrations.AddField( + model_name='user', + name='website', + field=models.URLField(null=True), + ), + ] diff --git a/limstagram/users/models.py b/limstagram/users/models.py index 8f07b15..82036d1 100644 --- a/limstagram/users/models.py +++ b/limstagram/users/models.py @@ -1,14 +1,24 @@ from django.contrib.auth.models import AbstractUser -from django.db.models import CharField +from django.db import models from django.urls import reverse from django.utils.translation import ugettext_lazy as _ class User(AbstractUser): + GENDER_CHOICES = ( + ('male', 'Male'), + ('female','Female'), + ('not-specified', 'Not specified') + ) + # First Name and Last Name do not cover name patterns # around the globe. - name = CharField(_("Name of User"), blank=True, max_length=255) + name = models.CharField(_("Name of User"), blank=True, max_length=255) + website = models.URLField(null=True) + bio = models.TextField(null=True) + phone = models.CharField(max_length=140, null=True) + gender = models.CharField(max_length=80, choices=GENDER_CHOICES, null=True) def get_absolute_url(self): return reverse("users:detail", kwargs={"username": self.username})