Skip to content

Instantly share code, notes, and snippets.

@colonelrascals
Created February 22, 2018 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colonelrascals/9a09d7aed7b238a12211577fa06e1743 to your computer and use it in GitHub Desktop.
Save colonelrascals/9a09d7aed7b238a12211577fa06e1743 to your computer and use it in GitHub Desktop.
Models
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from itertools import chain
import datetime
import hashlib
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django_mysql.models import JSONField, Model
from django.template.loader import render_to_string
from django.core.mail import send_mail
from django.utils import timezone
from django.conf import settings
class Bookmark(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
resource = models.ForeignKey("Resource", on_delete=models.CASCADE, related_name="bookmarks")
bookmark_groups = models.ManyToManyField("BookmarkGroup")
# meta
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ('user', 'resource',)
ordering = ('resource',)
def __str__(self):
return "{} | {}".format(self.user, self.resource)
class BookmarkGroup(models.Model):
name = models.CharField(max_length=50)
slug = models.SlugField(null=False, unique=True)
bmark = models.ManyToManyField(Bookmark)
def __str__(self):
return self.name
from __future__ import unicode_literals
import json
from django.shortcuts import render, get_list_or_404
from django.http import JsonResponse
from django.views import View
from django.views.generic import DetailView
from app.serializers import BookmarkGroupSerializer
from app.models import Resource,Bookmark,ResourceShare,PrivateNote,BookmarkGroup
from app.views.resources import get_enriched_resources
class BookmarkGroupView(DetailView):
model = BookmarkGroup
def get_context_data(self, **kwargs):
context = super(BookmarkGroupView, self).get_context_data(**kwargs)
print(context)
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment