Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solves issue 24: rename model fields #1

Merged
merged 1 commit into from
Jan 8, 2020
Merged
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
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()