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

[API] Create Model for Projects Enpoint #80

Closed
BethanyG opened this issue Feb 21, 2020 · 5 comments
Closed

[API] Create Model for Projects Enpoint #80

BethanyG opened this issue Feb 21, 2020 · 5 comments
Assignees
Labels
claimed enhancement New feature or request
Milestone

Comments

@BethanyG
Copy link
Member

Based on the current proposed projects JSON, create a projects model for the corresponding DB tables to support the projects DRF app.

JSON spec under discussion can be found in issue #77 , check there for any changes.

As of the writing of this issue, here is the JSON spec:

{    "fields":{
              "title":"webpack",
              "project creator":"Tobias Koppers",
              "description":"open-source JavaScript module bundler",
              "url":"https://github.com/webpack/webpack",
              "user":8,
              "date_published":"2019-09-19T04:29:04Z",
              "created":"2019-09-19T04:29:04.069Z",
              "modified":"2019-09-19T04:29:04Z",
              "open_to_contributors":true,
              "contributing cb members": [1, 9, 3, 8, 23, 19, 23],
              "tags": ["bundlers", "front end", "java script", "js", "tools"]
    			}
 }

Base on that spec, here is a rough model, assuming that certain fields (user, date fields, tags, description, guid) would follow the resources model for their constraints and data types.

import uuid
from taggit.managers import TaggableManager
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.contrib.auth import get_user_model


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


def get_tags_display(self):
    return self.tags.values_list('name', flat=True)


class Projects(models.Model):

    guid = models.UUIDField(default=uuid.uuid4, editable=False)

    title = models.CharField(max_length=200)

    project_creator = models.CharField(blank=True, max_length=200)

    description = models.TextField(blank=True, max_length=600)

    # specific URL of project home or github repo
    url = models.URLField(max_length=300)

    # user who posted the project
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user))

    #TO DO:  WHAT IS THIS FIELD FOR?  IS THIS THE PROJECT CREATION DATE??
    date_published = models.DateTimeField(default=timezone.now)

    # creation date of project entry
    created = models.DateTimeField(auto_now_add=True)

    # modification date of project entry
    modified = models.DateTimeField(default=timezone.now)

   #TO DO:  DEFINE FINAL DATA TYPE OF THIS FIELD
    open_to_contributors = models.BooleanField()

    #TO DO:  DEFINE RELATIONS FOR THIS FIELD
     contributing_cb_members = ?????

    # Allow tags to be used across entities
    # E.g. so we can create composite views showing all entities sharing a common tag
    tags = TaggableManager(blank=True)

    def __str__(self):
        """A string representation of the model."""
        return self.title
@BethanyG BethanyG added enhancement New feature or request question Further information is requested and removed question Further information is requested labels Feb 22, 2020
@billglover billglover added this to the projects milestone Feb 22, 2020
@BethanyG
Copy link
Member Author

BethanyG commented Mar 4, 2020

As of PR #96, the field to reference tags should change to the following:

tags = TaggableManager(through=TaggedItems, manager=CustomTaggableManager, blank=True)

This field for guid should use UUID1:

guid = models.UUIDField(default=uuid.uuid1, editable=False)

and the imports at the top of the projects/models.py file should be:

import uuid
from taggit.managers import TaggableManager
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.contrib.auth import get_user_model
from tagging.managers import CustomTaggableManager
from tagging.models import CustomTag, TaggedItems

@BethanyG
Copy link
Member Author

Closing as no longer relevant to current development.

@watchtheblur
Copy link
Member

Working on it now

@BethanyG
Copy link
Member Author

BethanyG commented Sep 7, 2020

@lpatmo -- should this be closed as a result of #170? Or are you keeping this open as a learning project (potentially reverting the PRs)/forking/branching etc.??

@lpatmo
Copy link
Member

lpatmo commented Sep 7, 2020

Fine to close! I thought the PR being merged would close the issue it was linked to directly 🤔 but note to self to double check (and make sure to loop back in the issue) 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
claimed enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants