Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.pythonPath": "/Users/JamesCassidy/.local/share/virtualenvs/Django-X-FuyRm-/bin/python",
"python.linting.pylintEnabled": false
}
20 changes: 20 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"
python-decouple = "*"
djangorestframework = "*"
django-cors-headers = "*"
gunicorn = "*"
psycopg2-binary = "*"
dj-database-url = "*"
whitenoise = "*"

[dev-packages]
"autopep8" = "*"

[requires]
python_version = "3.7"
134 changes: 134 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn djorg.wsgi --log-file -
Empty file added contacts/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions contacts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin

# Register your models here.
from django.contrib import admin
from .models import Contact, PersonalContact


class ContactAdmin(admin.ModelAdmin):
readonly_fields = ('created_at', 'last_modified')
# Register your models here.


admin.site.register(Contact, ContactAdmin)
admin.site.register(PersonalContact)
27 changes: 27 additions & 0 deletions contacts/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from rest_framework import serializers, viewsets
from .models import Contact, PersonalContact


class PersonalContactSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = PersonalContact
fields = ('title', 'content')

def create(self, validated_data):
user = self.context['request'].user
contact = PersonalContact.objects.create(user=user, **validated_data)
return contact


class PersonalContactViewSet(viewsets.ModelViewSet):
serializer_class = PersonalContactSerializer
queryset = PersonalContact.objects.none()

def get_queryset(self):
user = self.request.user

if user.is_anonymous:
return PersonalContact.objects.none()
else:
return PersonalContact.objects.filter(user=user)
5 changes: 5 additions & 0 deletions contacts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ContactsConfig(AppConfig):
name = 'contacts'
1 change: 1 addition & 0 deletions contacts/contacts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is about the data i'm storing
25 changes: 25 additions & 0 deletions contacts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.4 on 2018-12-06 21:30

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Contact',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('address', models.TextField(blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now=True)),
],
),
]
34 changes: 34 additions & 0 deletions contacts/migrations/0002_auto_20181206_2154.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.1.4 on 2018-12-06 21:54

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contacts', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='PersonalContact',
fields=[
('contact_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='contacts.Contact')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
bases=('contacts.contact',),
),
migrations.RenameField(
model_name='contact',
old_name='address',
new_name='content',
),
migrations.RenameField(
model_name='contact',
old_name='name',
new_name='title',
),
]
Empty file added contacts/migrations/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions contacts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models
from uuid import uuid4

from django.contrib.auth.models import User

# Create your models here.


class Contact(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
title = models.CharField(max_length=200)
content = models.TextField(blank=True)

created_at = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)


class PersonalContact(Contact):
user = models.ForeignKey(User, on_delete=models.CASCADE)
3 changes: 3 additions & 0 deletions contacts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions contacts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Binary file added db.sqlite3
Binary file not shown.
Empty file added djorg/__init__.py
Empty file.
Loading