diff --git a/conduit/apps/articles/admin.py b/conduit/apps/articles/admin.py new file mode 100644 index 0000000..a859fef --- /dev/null +++ b/conduit/apps/articles/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Article, Comment, Tag + +admin.site.register(Article) +admin.site.register(Comment) +admin.site.register(Tag) diff --git a/conduit/apps/authentication/admin.py b/conduit/apps/authentication/admin.py new file mode 100644 index 0000000..c4a654c --- /dev/null +++ b/conduit/apps/authentication/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import User + +admin.site.register(User) diff --git a/conduit/apps/authentication/serializers.py b/conduit/apps/authentication/serializers.py index d9894ce..cb5e324 100644 --- a/conduit/apps/authentication/serializers.py +++ b/conduit/apps/authentication/serializers.py @@ -99,7 +99,7 @@ def validate(self, data): class UserSerializer(serializers.ModelSerializer): """Handles serialization and deserialization of User objects.""" - # Passwords must be at least 8 characters, but no more than 128 + # Passwords must be at least 8 characters, but no more than 128 # characters. These values are the default provided by Django. We could # change them, but that would create extra work while introducing no real # benefit, so let's just stick with the defaults. @@ -113,7 +113,7 @@ class UserSerializer(serializers.ModelSerializer): # so. Moreover, `UserSerializer` should never expose profile information, # so we set `write_only=True`. profile = ProfileSerializer(write_only=True) - + # We want to get the `bio` and `image` fields from the related Profile # model. bio = serializers.CharField(source='profile.bio', read_only=True) @@ -122,7 +122,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ( - 'email', 'username', 'password', 'token', 'profile', 'bio', + 'email', 'username', 'password', 'token', 'profile', 'bio', 'image', ) @@ -130,7 +130,7 @@ class Meta: # specifying the field with `read_only=True` like we did for password # above. The reason we want to use `read_only_fields` here is because # we don't need to specify anything else about the field. For the - # password field, we needed to specify the `min_length` and + # password field, we needed to specify the `min_length` and # `max_length` properties too, but that isn't the case for the token # field. read_only_fields = ('token',) @@ -169,7 +169,7 @@ def update(self, instance, validated_data): # We're doing the same thing as above, but this time we're making # changes to the Profile model. setattr(instance.profile, key, value) - + # Save the profile just like we saved the user. instance.profile.save() diff --git a/conduit/apps/authentication/views.py b/conduit/apps/authentication/views.py index b12d867..112c62f 100644 --- a/conduit/apps/authentication/views.py +++ b/conduit/apps/authentication/views.py @@ -82,4 +82,3 @@ def update(self, request, *args, **kwargs): serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) - diff --git a/conduit/apps/core/admin.py b/conduit/apps/core/admin.py new file mode 100644 index 0000000..8800038 --- /dev/null +++ b/conduit/apps/core/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import TimestampedModel + +# admin.site.register(TimestampedModel) diff --git a/conduit/apps/profiles/admin.py b/conduit/apps/profiles/admin.py new file mode 100644 index 0000000..d914f1f --- /dev/null +++ b/conduit/apps/profiles/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Profile + +admin.site.register(Profile) diff --git a/conduit/apps/profiles/migrations/0004_auto_20190930_2347.py b/conduit/apps/profiles/migrations/0004_auto_20190930_2347.py new file mode 100644 index 0000000..1b55615 --- /dev/null +++ b/conduit/apps/profiles/migrations/0004_auto_20190930_2347.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-09-30 18:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0003_profile_favorites'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='image', + field=models.FileField(blank=True, upload_to='profile_pictures'), + ), + ] diff --git a/conduit/apps/profiles/migrations/0005_auto_20190930_2355.py b/conduit/apps/profiles/migrations/0005_auto_20190930_2355.py new file mode 100644 index 0000000..17b0933 --- /dev/null +++ b/conduit/apps/profiles/migrations/0005_auto_20190930_2355.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-09-30 18:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0004_auto_20190930_2347'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='favorites', + field=models.ManyToManyField(blank=True, related_name='favorited_by', to='articles.Article'), + ), + migrations.AlterField( + model_name='profile', + name='follows', + field=models.ManyToManyField(blank=True, related_name='followed_by', to='profiles.Profile'), + ), + ] diff --git a/conduit/apps/profiles/migrations/0006_auto_20191001_0059.py b/conduit/apps/profiles/migrations/0006_auto_20191001_0059.py new file mode 100644 index 0000000..5febd26 --- /dev/null +++ b/conduit/apps/profiles/migrations/0006_auto_20191001_0059.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-09-30 19:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0005_auto_20190930_2355'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='image', + field=models.URLField(blank=True), + ), + ] diff --git a/conduit/apps/profiles/migrations/0007_auto_20191001_0105.py b/conduit/apps/profiles/migrations/0007_auto_20191001_0105.py new file mode 100644 index 0000000..4a97f10 --- /dev/null +++ b/conduit/apps/profiles/migrations/0007_auto_20191001_0105.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-09-30 19:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0006_auto_20191001_0059'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='image', + field=models.FileField(blank=True, upload_to='profile_pictures'), + ), + ] diff --git a/conduit/apps/profiles/migrations/0008_auto_20191001_0108.py b/conduit/apps/profiles/migrations/0008_auto_20191001_0108.py new file mode 100644 index 0000000..98717d1 --- /dev/null +++ b/conduit/apps/profiles/migrations/0008_auto_20191001_0108.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-09-30 19:38 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profiles', '0007_auto_20191001_0105'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='image', + field=models.URLField(blank=True), + ), + ] diff --git a/conduit/apps/profiles/models.py b/conduit/apps/profiles/models.py index 6c47aa8..1a3409f 100644 --- a/conduit/apps/profiles/models.py +++ b/conduit/apps/profiles/models.py @@ -20,6 +20,7 @@ class Profile(TimestampedModel): # In addition to the `bio` field, each user may have a profile image or # avatar. Similar to `bio`, this field is not required. It may be blank. image = models.URLField(blank=True) + #image=models.FileField(upload_to='profile_pictures', blank=True) # This is an example of a Many-To-Many relationship where both sides of the # relationship are of the same model. In this case, the model is `Profile`. @@ -29,12 +30,14 @@ class Profile(TimestampedModel): follows = models.ManyToManyField( 'self', related_name='followed_by', - symmetrical=False + symmetrical=False, + blank=True ) favorites = models.ManyToManyField( 'articles.Article', - related_name='favorited_by' + related_name='favorited_by', + blank=True ) diff --git a/conduit/apps/profiles/serializers.py b/conduit/apps/profiles/serializers.py index b799082..3f7d21f 100644 --- a/conduit/apps/profiles/serializers.py +++ b/conduit/apps/profiles/serializers.py @@ -6,7 +6,6 @@ class ProfileSerializer(serializers.ModelSerializer): username = serializers.CharField(source='user.username') bio = serializers.CharField(allow_blank=True, required=False) - image = serializers.SerializerMethodField() following = serializers.SerializerMethodField() class Meta: @@ -14,12 +13,6 @@ class Meta: fields = ('username', 'bio', 'image', 'following',) read_only_fields = ('username',) - def get_image(self, obj): - if obj.image: - return obj.image - - return 'https://static.productionready.io/images/smiley-cyrus.jpg' - def get_following(self, instance): request = self.context.get('request', None) diff --git a/conduit/settings.py b/conduit/settings.py index 17b2df7..9fc0218 100644 --- a/conduit/settings.py +++ b/conduit/settings.py @@ -23,9 +23,9 @@ SECRET_KEY = '2^f+3@v7$v1f8yt0!s)3-1t$)tlp+xm17=*g))_xoi&&9m#2a&' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Application definition @@ -129,6 +129,7 @@ STATIC_URL = '/static/' + CORS_ORIGIN_WHITELIST = ( '0.0.0.0:4000', 'localhost:4000',