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

tutorial part 3 #64

Closed
KushGrandhi opened this issue Jun 27, 2020 · 8 comments
Closed

tutorial part 3 #64

KushGrandhi opened this issue Jun 27, 2020 · 8 comments

Comments

@KushGrandhi
Copy link

KushGrandhi commented Jun 27, 2020

in models.py

class Book(models.Model):
title = models.CharField(max_length=200)

author = models.ForeignKey('Author', on_delete=models.SET_NULL, null = True)

summary = models.TextField(max_length = 1000, help_text= 'Enter a brief description of the book')

isbn = models.CharField(
    'ISBN', max_length=13, help_text='13 character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>')

genre = models.ManyToManyField(Genre, help_text = 'Select a genre for this book')

def __str__(self):
    return self.title

def get_absolute_url(self):
    return reverse('book-details', args=[str(self.id)])

there is no self.id in class Book and is giving an error
the get_absolute url seems to not work as the foriegn keys are not getting linked somehow

@hamishwillee
Copy link
Collaborator

Is this failing on this repo or your own version?
I assure you that Book does have self.id - every model has one auto created by default.

@KushGrandhi
Copy link
Author

KushGrandhi commented Jun 29, 2020

i suppose the problem is with my own version
i copy pasted the code and tried as well, but still it was failing for me.

@hamishwillee
Copy link
Collaborator

No, I mean if you try this particular repo code in all its glory, does it work?

@KushGrandhi
Copy link
Author

no, still it shows the same error.

@hamishwillee
Copy link
Collaborator

OK, so this all works and builds fine with the right environment, so probably you have just imported the current requirements/versions as you have gone through the tutorial. One of these has been updated since the tutorial was written, breaking the code.

You can test this by creating a clean environment, then import the requirements.txt/follow the steps as shown in https://github.com/mdn/django-locallibrary-tutorial#quick-start

If that works then you've done nothing wrong in your code and the example will need and update. If it does not work then i'm a bit stumped.

@KushGrandhi
Copy link
Author

Yes it seems to work now with the quick setup but when i opened vscode it still shows errors, i don’t understand whats wrong

@hamishwillee
Copy link
Collaborator

The fact it works tells us that one of the dependencies has changed since the tutorial was created, and now that part of the code (and the dependencies) should be updated. To find out which, you look at https://github.com/mdn/django-locallibrary-tutorial/blob/master/requirements.txt
Then in your old environment you compare to see what has changed. For example, what version of Django are you using?

Also note that VSCode reporting errors is not something I can help with - I coded this in a text editor.

@KushGrandhi
Copy link
Author

the only difference in my old environment was that django version was 2.2 as 2.1 has been deprecated.
Thank you so much for the help!

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

No branches or pull requests

2 participants