0

I have models for eg like this.

class Mp3(models.Model):
    title=models.CharField(max_length=30)
    artist=models.ForeignKey('Artist')

and Here is how the Artist models looks like:

alert(1)
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Nov 4, 2021 at 14:27

2 Answers 2

1
class Artist(models.Model):
    name = models.CharField(max_length=30)
class Mp3(models.Model):
    title = models.CharField(max_length=30)
    artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
Sign up to request clarification or add additional context in comments.

1 Comment

do you want to save model in django with foreign key in views
0

I ended up with

class Mp3(models.Model):
    title = models.CharField(max_length=30)
    artist = models.ForeignKey(Artist, on_delete=models.CASCADE)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.