Skip to content

Commit

Permalink
Merge pull request #1 from codebuddies/issue-24
Browse files Browse the repository at this point in the history
Solves issue 24: rename model fields
  • Loading branch information
BethanyG authored Jan 8, 2020
2 parents e938a7f + 862118a commit 0898e19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
30 changes: 19 additions & 11 deletions cbv3_django_prototype/cbv3_django_prototype/resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
import django.contrib.postgres.fields as pg
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.conf import settings


def get_sentinel_user():
return get_user_model().objects.get_or_create(username='deleted')[0]


class Resource(models.Model):
Expand All @@ -19,23 +26,28 @@ class Resource(models.Model):
('TOOL', 'Tool'),
('LIB', 'Library'),
('WEB', 'Website')
]
]

id = models.UUIDField(primary_key=True, default=uuid.uuid1, editable=False)

title = models.CharField(max_length=200)

#potentially a markdown field. Will need a markdown converter and renderer
author = models.CharField(max_length=200, blank=True)

# potentially a markdown field. Will need a markdown converter and renderer
description = models.TextField(blank=True, max_length=500)

#specific URL of resource
# specific URL of resource
url = models.URLField(max_length=300)

#the URL of the referring/source site. e.g. URL of tweet, if it was tweeted.
referrer = models.URLField(blank=True, max_length=300)
# the URL of the referring/source site. e.g. URL of tweet, if it was tweeted.
referring_url = models.URLField(blank=True, max_length=300)

# names of persons who suggest this resource to the user
referring_user = models.CharField(max_length=100)

#names of persons who suggest this resource to the user
credit = models.CharField(max_length=100)
# user who posted the resource
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user))

# publication date of resource
date_published = models.DateTimeField(default=timezone.now)
Expand All @@ -54,10 +66,6 @@ class Resource(models.Model):
# JSONB for a simplified DB Schema and prototype for now.
tags = pg.JSONField()




def __str__(self):
"""A string representation of the model."""
return self.title

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers
from .models import Resource


class ResourceSerializer(serializers.ModelSerializer):
media_type = serializers.SerializerMethodField()

Expand All @@ -9,6 +10,7 @@ class Meta:

fields = (
'id',
'author',
'title',
'description',
'url',
Expand All @@ -24,4 +26,3 @@ class Meta:

def get_media_type(self, obj):
return obj.get_media_type_display()

0 comments on commit 0898e19

Please sign in to comment.