Skip to content

Commit 3135dd6

Browse files
committed
Created a migration for the codecorgi profile
1 parent c665afc commit 3135dd6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

api/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import string
2+
import random
3+
4+
def id_generator(size=18, chars=string.ascii_uppercase + string.digits):
5+
return ''.join(random.choice(chars) for _ in range(size))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from django.db import migrations, models
2+
from api.utils import id_generator
3+
4+
def create_codecorgi_profile(apps, schema_editor):
5+
User = apps.get_model('accounts', 'User')
6+
Profile = apps.get_model('profile', 'Profile')
7+
8+
corgiUser = User.objects.create(
9+
password=id_generator(),
10+
11+
is_verified=True,
12+
is_admin=True,
13+
username='codecorgi',
14+
)
15+
16+
Profile.objects.create(
17+
tagline = 'Woof Woof',
18+
bio = 'Coder\'s best friend',
19+
___location = 'Brooklyn, NY',
20+
linkedin_url = 'https://www.linkedin.com/company/codecorgi',
21+
twitter_url = 'https://twitter.com/codecorgi',
22+
github_url = 'https://github.com/corgicode',
23+
company = 'codecorgi',
24+
blog = 'https://medium.com/@codecorgi',
25+
public_repos = 'https://github.com/code-corgi',
26+
hireable = False,
27+
user = corgiUser,
28+
name = 'Corginson',
29+
avatar_url = 'https://raw.githubusercontent.com/corgicode/frontend-react/dev/src/assets/images/logo-square-hover.png',
30+
hero_image_url = 'https://raw.githubusercontent.com/corgicode/frontend-react/dev/src/assets/images/hero-image.jpg',
31+
)
32+
33+
def delete_codecorgi_profile(apps, schema_editor):
34+
User = apps.get_model('accounts', 'User')
35+
Profile = apps.get_model('profile', 'Profile')
36+
37+
corgiUser = User.objects.filter(email='[email protected]').first()
38+
Profile.objects.filter(user_id=corgiUser.id).delete()
39+
corgiUser.delete()
40+
41+
42+
class Migration(migrations.Migration):
43+
dependencies = [
44+
('profile', '0001_initial')
45+
]
46+
47+
operations = [
48+
migrations.RunPython(create_codecorgi_profile, delete_codecorgi_profile),
49+
]

0 commit comments

Comments
 (0)