Skip to content

Commit

Permalink
Users, images 모델 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
geun lim authored and geun lim committed Jul 24, 2018
1 parent e08c218 commit 2f99d86
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 5 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
40 changes: 40 additions & 0 deletions limstagram/images/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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,
},
),
]
16 changes: 16 additions & 0 deletions limstagram/images/models.py
Original file line number Diff line number Diff line change
@@ -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()

33 changes: 33 additions & 0 deletions limstagram/users/migrations/0002_auto_20180724_2012.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
14 changes: 12 additions & 2 deletions limstagram/users/models.py
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 2f99d86

Please sign in to comment.