Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code doctor test #55

Open
wants to merge 378 commits into
base: initial_commit
Choose a base branch
from
Open

code doctor test #55

wants to merge 378 commits into from

Conversation

cb109
Copy link
Owner

@cb109 cb109 commented Jan 8, 2022

No description provided.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Worth considering though. View full project report here.

Comment on lines +66 to +68
avatar_image_url = models.CharField(
max_length=1024, null=True, blank=True, default=DEFAULT_AVATAR_URL
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
avatar_image_url = models.CharField(
max_length=1024, null=True, blank=True, default=DEFAULT_AVATAR_URL
)
avatar_image_url = models.TextField(blank=True, default="")

TextField might be better used here, instead of CharField with a huge max_length. More info.

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="". More.

"""A membership is a mapping of a user to a collective."""

member = models.ForeignKey("auth.User", on_delete=models.CASCADE)
collective = models.ForeignKey("purchases.Collective", on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. Read more.

name = models.CharField(max_length=100)
price = MoneyField(max_digits=10, decimal_places=2, default_currency="EUR")
buyer = models.ForeignKey("auth.User", on_delete=models.CASCADE)
collective = models.ForeignKey("purchases.Collective", on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with an explicit related_name would be better.

creditor = models.ForeignKey(
"auth.User", related_name="creditor", on_delete=models.CASCADE
)
collective = models.ForeignKey("purchases.Collective", on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, with an explicit related_name would be better.

unique_together = ("member", "collective")

def __str__(self):
return u"{} in {}".format(self.member.username, self.collective.name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More details.

reactions = GenericRelation(Reaction)

def __str__(self):
return u"{} for {} by {} in {}".format(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, Consider using f-string instead.

reactions = GenericRelation(Reaction)

def __str__(self):
return u"{} from {} to {} in {}".format(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, Consider using f-string instead.

Copy link

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.



class PurchaseWeight(TimestampMixin, models.Model):
purchase = models.ForeignKey("purchases.Purchase", on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django automatically creates a related_name if it's not set. If it were set then a more readable and explicit relationship is set up. More details.


class PurchaseWeight(TimestampMixin, models.Model):
purchase = models.ForeignKey("purchases.Purchase", on_delete=models.CASCADE)
member = models.ForeignKey("auth.User", on_delete=models.CASCADE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, with an explicit related_name would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants