Skip to content

Instantly share code, notes, and snippets.

@tonybaloney
Last active December 29, 2019 13:56
Show Gist options
  • Save tonybaloney/a7f072e9f5aadb249dd3504d9bd068bc to your computer and use it in GitHub Desktop.
Save tonybaloney/a7f072e9f5aadb249dd3504d9bd068bc to your computer and use it in GitHub Desktop.
import uuid
from django.db import models
from django.contrib.auth import get_user_model
class Badge(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
label = models.CharField(max_length=255)
description = models.TextField()
slug = models.CharField(max_length=25)
required_path = models.CharField(max_length=255)
image_url = models.CharField(max_length=255)
def __str__(self):
return self.label
class AwardedBadge(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
badge = models.ForeignKey(
'Badge',
on_delete=models.CASCADE,
)
user = models.ForeignKey(
get_user_model(),
on_delete=models.CASCADE,
)
issued_date = models.DateTimeField(auto_now=True)
def __str__(self):
return "{0} issued to {1}".format(str(self.badge), str(self.user))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment