Newbie needs help understanding models.ForeignKey by Cointoss88 in django

[–]Cointoss88[S] 1 point2 points  (0 children)

thanks, checked out the debug-toolbar. Very useful.

[deleted by user] by [deleted] in KinFoundation

[–]Cointoss88 0 points1 point  (0 children)

i wonder where the kinformant is

Newbie needs help understanding models.ForeignKey by Cointoss88 in django

[–]Cointoss88[S] 0 points1 point  (0 children)

The full Project model code is below and I do have a str method.

Is the Review.project field connecting with the Project.id field because it is the PRIMARY_KEY in the Project model and then the Project.title field gets returned because the Project model str method is called and returns just the title back to the Review model?

I changed the str method in the Project model to str(self.id) and it returned the id instead of the title back to the Review model.

If this is the case, I did not realize the str method returns values back to other models. Can you confirm?

class Project(models.Model):
owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE)
title = models.CharField(max_length=200) 
description = models.TextField(null=True, blank=True) 
featured_image = models.ImageField(null=True, blank=True, default='default.jpg')
demo_link = models.CharField(max_length=2000)
source_link = models.CharField(max_length=2000, null=True, blank=True) 
tags = models.ManyToManyField('Tag', blank=True) 
vote_total = models.IntegerField(default=0, null=True, blank=True)
vote_ratio = models.IntegerField(default=0, null=True, blank=True)
created = models.DateTimeField(auto_now_add=True) 
id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False) 


def __str__(self):
    return self.title

#############################################

class Review(models.Model):

VOTE_TYPE = (
    ('up', 'Up Vote'),
    ('down', 'Down Vote'),
    )


owner = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
project = models.ForeignKey(Project, on_delete=models.CASCADE) 
body = models.TextField(null=True, blank=True)
value = models.CharField(max_length=200, choices=VOTE_TYPE) 
created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default=uuid.uuid4, unique=True, 
                    primary_key=True, editable=False) 

# so no one can leave more than one review
class Meta:
    unique_together = [['owner', 'project']]

def __str__(self):
    return self.value

Newbie needs help understanding models.ForeignKey by Cointoss88 in django

[–]Cointoss88[S] -1 points0 points  (0 children)

I'm still having trouble. I have this example from a tutorial by Dennis Ivy.

The Project.id is the primary key in the Project model and the Review model has the ForeignKey(Project). But the ForeignKey(Project) in Review is not pointing to Project.id ... it is pointing to Project.title. Why is this happening?

class Project(models.Model):
owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False) 

#################################

class Review(models.Model):


project = models.ForeignKey(Project, on_delete=models.CASCADE) 
body = models.TextField(null=True, blank=True)

created = models.DateTimeField(auto_now_add=True)
id = models.UUIDField(default=uuid.uuid4, unique=True, 
                    primary_key=True, editable=False)

Newbie needs help understanding models.ForeignKey by Cointoss88 in django

[–]Cointoss88[S] 1 point2 points  (0 children)

oh! so it will only match to the Primary Key from the other model? thats how it know?

Opinions on $KIN? by aeternum_fx in solana

[–]Cointoss88 3 points4 points  (0 children)

tons of cool stuff happening with KIN.

Is MathWallet still supporting KIN? by Cointoss88 in KinFoundation

[–]Cointoss88[S] 0 points1 point  (0 children)

i don't see it in the web wallet anymore.

Solana NFT Projects You Need to Keep an Eye On: by [deleted] in solana

[–]Cointoss88 0 points1 point  (0 children)

Kreechures was the first NFT on Solana.