Models
class Badge(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=200)
icon = models.ImageField(upload_to='badges/icons/', blank=True, null=True)
createdAt = models.DateTimeField(auto_now_add=True)
Model to assign badges to users (many-to-many relation)
class UserBadge(models.Model):
user = models.ForeignKey('authAPI.User', on_delete=models.CASCADE)
badge = models.ForeignKey(Badge, on_delete=models.CASCADE)
awardedAt = models.DateTimeField(auto_now_add=True)
User-Badge relation have Many to Many
Models class Badge(models.Model): name = models.CharField(max_length=50, unique=True) description = models.CharField(max_length=200) icon = models.ImageField(upload_to='badges/icons/', blank=True, null=True) createdAt = models.DateTimeField(auto_now_add=True)
Model to assign badges to users (many-to-many relation) class UserBadge(models.Model): user = models.ForeignKey('authAPI.User', on_delete=models.CASCADE) badge = models.ForeignKey(Badge, on_delete=models.CASCADE) awardedAt = models.DateTimeField(auto_now_add=True)