Skip to content

Commit

Permalink
Added Tags field to the project models (#2605)
Browse files Browse the repository at this point in the history
* added the tag feature

* added tags field

* migrations
  • Loading branch information
Uttkarsh-raj authored Aug 6, 2024
1 parent 23bfd40 commit d2486e6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Subscription,
Suggestion,
SuggestionVotes,
Tag,
Transaction,
UserProfile,
Wallet,
Expand Down Expand Up @@ -345,3 +346,4 @@ class ProjectAdmin(admin.ModelAdmin):
admin.site.register(IP, IPAdmin)
admin.site.register(Transaction)
admin.site.register(Monitor, MonitorAdmin)
admin.site.register(Tag)
32 changes: 32 additions & 0 deletions website/migrations/0123_tag_issue_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.0.7 on 2024-08-06 07:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0122_rename_user_agent_string_ip_agent"),
]

operations = [
migrations.CreateModel(
name="Tag",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
],
),
migrations.AddField(
model_name="issue",
name="tags",
field=models.ManyToManyField(blank=True, related_name="tags", to="website.tag"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 5.0.7 on 2024-08-06 15:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("website", "0123_tag_issue_tags"),
]

operations = [
migrations.AddField(
model_name="company",
name="tags",
field=models.ManyToManyField(blank=True, to="website.tag"),
),
migrations.AddField(
model_name="domain",
name="tags",
field=models.ManyToManyField(blank=True, to="website.tag"),
),
migrations.AddField(
model_name="project",
name="tags",
field=models.ManyToManyField(blank=True, to="website.tag"),
),
migrations.AddField(
model_name="userprofile",
name="tags",
field=models.ManyToManyField(blank=True, to="website.tag"),
),
migrations.AlterField(
model_name="issue",
name="tags",
field=models.ManyToManyField(blank=True, to="website.tag"),
),
]
12 changes: 12 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class Subscription(models.Model):
created = models.DateTimeField(auto_now_add=True)


class Tag(models.Model):
name = models.CharField(max_length=255)

def __str__(self):
return self.name


class Company(models.Model):
admin = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE)
managers = models.ManyToManyField(User, related_name="user_companies")
Expand All @@ -58,6 +65,7 @@ class Company(models.Model):
modified = models.DateTimeField(auto_now=True)
subscription = models.ForeignKey(Subscription, null=True, blank=True, on_delete=models.CASCADE)
is_active = models.BooleanField(default=False)
tags = models.ManyToManyField(Tag, blank=True)

def __str__(self):
return self.name
Expand All @@ -79,6 +87,7 @@ class Domain(models.Model):
facebook = models.URLField(null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
tags = models.ManyToManyField(Tag, blank=True)

def __unicode__(self):
return self.name
Expand Down Expand Up @@ -270,6 +279,7 @@ class Issue(models.Model):
reporter_ip_address = models.GenericIPAddressField(null=True, blank=True)
cve_id = models.CharField(max_length=16, null=True, blank=True)
cve_score = models.DecimalField(max_digits=2, decimal_places=1, null=True, blank=True)
tags = models.ManyToManyField(Tag, blank=True)

def __unicode__(self):
return self.description
Expand Down Expand Up @@ -502,6 +512,7 @@ class UserProfile(models.Model):
bch_address = models.CharField(max_length=100, blank=True, null=True)
eth_address = models.CharField(max_length=100, blank=True, null=True)
created = models.DateTimeField(auto_now_add=True)
tags = models.ManyToManyField(Tag, blank=True)

def avatar(self, size=36):
if self.user_avatar:
Expand Down Expand Up @@ -714,6 +725,7 @@ class Project(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
contributors = models.ManyToManyField(Contributor, related_name="projects", blank=True)
tags = models.ManyToManyField(Tag, blank=True)

def __str__(self):
return self.name
Expand Down
7 changes: 7 additions & 0 deletions website/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Issue,
Points,
Project,
Tag,
User,
UserProfile,
)
Expand Down Expand Up @@ -67,6 +68,12 @@ class Meta:
)


class TagSerializer(serializers.ModelSerializer):
class Meta:
model = Tag
fields = "__all__"


class IssueSerializer(serializers.ModelSerializer):
"""
Serializer for Issue Model
Expand Down

0 comments on commit d2486e6

Please sign in to comment.