유저 테이블
rom django.db import models
14 class User(models.Model):
13 email = models.EmailField(max_length=100, unique=True)
12 password = models.CharField(max_length=200)
11 name = models.CharField(max_length=45)
10 phone_number = models.CharField(max_length=45, unique=True)
9 is_active = models.BooleanField(default=True)
8 mileage = models.IntegerField()
7 coupon = models.ManyToManyField('Coupon', through='UserCoupon')
6 wish = models.ManyToManyField('products.Product', through='WishList')
5 created_at = models.DateTimeField(auto_now_add=True)
4 updated_at = models.DateTimeField(auto_now=True)
3 class Meta:
2 ¦ db_table = 'users'
1 class Address(models.Model):
16 user = models.ForeignKey(User, on_delete=models.CASCADE)
1 postal_code = models.CharField(max_length=45)
2 main_address = models.CharField(max_length=100)
3 detail_address = models.CharField(max_length=100)
4 is_main = models.BooleanField()
5 phone_number = models.CharField(max_length=45)
6 class Meta:
7 ¦ db_table = 'addresses'
mysql
mysql> create database whiteSpace_1 character set utf8mb4 collate utf8mb4_general_ci;
mysql> use whiteSpace_1
mysql> select * from users;
+----+------------------------+-------------+-----------+---------------+-----------+---------+----------------------------+----------------------------+
| id | email | password | name | phone_number | is_active | mileage | created_at | updated_at |
+----+------------------------+-------------+-----------+---------------+-----------+---------+----------------------------+----------------------------+
| 1 | ewfwfwffwfe@naver.com | 23423423423 | 홍태경 | 01023245564 | 1 | 0 | 2021-04-14 12:00:05.779725 | 2021-04-14 12:00:05.779849 |
| 2 | ewfwfwff1231@naver.com | 234234213 | 임꺽정 | 010232452344 | 1 | 0 | 2021-04-14 12:00:25.942399 | 2021-04-14 12:00:25.942524 |
| 4 | ewfwfwff1231@234com | 2342342133 | 친구 | 0103232452344 | 1 | 0 | 2021-04-14 12:00:55.376867 | 2021-04-14 12:00:55.376987 |
+----+------------------------+-------------+-----------+---------------+-----------+---------+----------------------------+----------------------------+
3 rows in set (0.00 sec)
>>> user = User.objects.get(pk=1)
>>> a = Address(user = user, postal_code ='4224243423', main_address="서울시 짱구", detail_address="4242344423", is_main = True, phone_number="2442423424")
>>> a
<Address: Address object (None)>
>>>user
<User: User object(4)
>>>user.address_set_all()
<QuerySet[]>
a.save()
<QuerySet[<Address:Address object (3)>]>