Skip to content

Commit

Permalink
fix: avoid error when creating same model names with different users
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloUbirajara committed Apr 28, 2024
1 parent 4a29307 commit 751b6a0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion apps/category/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class Category(models.Model):

user = models.ForeignKey(to="auth.User", on_delete=models.CASCADE)

name = models.TextField(unique=True)
name = models.TextField()

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
unique_together = ["name", "user"]
ordering = ["-updated_at"]
1 change: 1 addition & 0 deletions apps/transaction/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class Transaction(models.Model):
updated_at = models.DateTimeField(auto_now=True)

class Meta:
unique_together = ["name", "user"]
ordering = ["-updated_at"]
3 changes: 2 additions & 1 deletion apps/wallet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Wallet(models.Model):
user = models.ForeignKey(to="auth.User", on_delete=models.CASCADE)
currency = models.ForeignKey(to="currency.Currency", on_delete=models.CASCADE)

name = models.TextField(unique=True)
name = models.TextField()
description = models.TextField(blank=True, default="")

created_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -19,4 +19,5 @@ def __str__(self) -> str:
return "{} ({})".format(self.name, self.id)

class Meta:
unique_together = ["name", "user"]
ordering = ["-updated_at"]

0 comments on commit 751b6a0

Please sign in to comment.