Skip to content

Commit 61c9d55

Browse files
watchtheblurlpatmo
authored andcommitted
created models for osprojects
1 parent 159725c commit 61c9d55

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

project/config/settings/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
"users.apps.UsersConfig",
8989
"resources.apps.ResourcesConfig",
9090
"tagging.apps.TaggingConfig",
91-
'userauth.apps.UserauthConfig'
91+
'userauth.apps.UserauthConfig',
92+
'osprojects.apps.OsprojectsConfig'
9293
# Your stuff: custom apps go here
9394
]
9495
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 2.2.4 on 2020-08-27 00:36
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
import django.utils.timezone
6+
import osprojects.models
7+
import taggit.managers
8+
import uuid
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
initial = True
14+
15+
dependencies = [
16+
('tagging', '0003_auto_20200508_1230'),
17+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
18+
]
19+
20+
operations = [
21+
migrations.CreateModel(
22+
name='OSProjects',
23+
fields=[
24+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
25+
('guid', models.UUIDField(default=uuid.uuid1, editable=False)),
26+
('title', models.CharField(max_length=200)),
27+
('project_creator', models.CharField(blank=True, max_length=200)),
28+
('description', models.TextField(blank=True, max_length=600)),
29+
('url', models.URLField(max_length=300)),
30+
('created', models.DateTimeField(auto_now_add=True)),
31+
('modified', models.DateTimeField(default=django.utils.timezone.now)),
32+
('open_to_contributors', models.BooleanField()),
33+
('tags', taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='tagging.TaggedItems', to='tagging.CustomTag', verbose_name='Tags')),
34+
('user', models.ForeignKey(on_delete=models.SET(osprojects.models.get_sentinel_user), to=settings.AUTH_USER_MODEL)),
35+
],
36+
),
37+
]

project/osprojects/models.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
1+
import uuid
2+
from taggit.managers import TaggableManager
3+
from django.conf import settings
14
from django.db import models
5+
from django.utils import timezone
6+
from django.contrib.auth import get_user_model
7+
from tagging.managers import CustomTaggableManager
8+
from tagging.models import CustomTag, TaggedItems
29

3-
# Create your models here.
10+
def get_sentinel_user():
11+
return get_user_model().objects.get_or_create(username='deleted')[0]
12+
13+
14+
def get_tags_display(self):
15+
return self.tags.values_list('name', flat=True)
16+
17+
18+
class OSProjects(models.Model):
19+
20+
guid = models.UUIDField(default=uuid.uuid1, editable=False)
21+
22+
title = models.CharField(max_length=200)
23+
24+
project_creator = models.CharField(blank=True, max_length=200)
25+
26+
description = models.TextField(blank=True, max_length=600)
27+
28+
# specific URL of project home or github repo
29+
url = models.URLField(max_length=300)
30+
31+
# user who posted the project
32+
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user))
33+
34+
# creation date of project entry
35+
created = models.DateTimeField(auto_now_add=True)
36+
37+
# modification date of project entry
38+
modified = models.DateTimeField(default=timezone.now)
39+
40+
# TO DO: DEFINE FINAL DATA TYPE OF THIS FIELD
41+
open_to_contributors = models.BooleanField()
42+
43+
# TO DO: DEFINE RELATIONS FOR THIS FIELD
44+
# contributing_cb_members = ?????
45+
46+
# Allow tags to be used across entities
47+
# E.g. so we can create composite views showing all entities sharing a common tag
48+
tags = TaggableManager(through=TaggedItems, manager=CustomTaggableManager, blank=True)
49+
50+
def __str__(self):
51+
"""A string representation of the model."""
52+
return self.title

0 commit comments

Comments
 (0)