Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

[API] Create Model for Projects Enpoint #80

Closed

Description

@BethanyG

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

Activity

  1. added
    enhancement
    question
    and removed
    question
    on Feb 22, 2020
  2. added this to the projects milestone on Feb 22, 2020
  3. BethanyG commented on Mar 4, 2020

    @BethanyG
    MemberAuthor

    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
  4. BethanyG commented on Aug 16, 2020

    @BethanyG
    MemberAuthor

    Closing as no longer relevant to current development.

  5. watchtheblur commented on Aug 27, 2020

    @watchtheblur
    Member

    Working on it now

  6. BethanyG commented on Sep 7, 2020

    @BethanyG
    MemberAuthor

    @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.??

  7. lpatmo commented on Sep 7, 2020

    @lpatmo
    Member

    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

Metadata

Metadata

Assignees

Labels

claimedenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions