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

Model class django_comments.models.Comment doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS #270

Closed
ogurec-ogurec opened this issue Dec 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ogurec-ogurec
Copy link

When trying to add COMMENT_PROFILE_API_FIELDS in settings.py:

PROFILE_APP_NAME = 'users'
PROFILE_MODEL_NAME = 'Profile'

I get an error when entering the url: localhost/profile
Model class django_comments.models.Comment doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

When I try to log into the post_detail page, I get the following error:

AttributeError at /post/testpost 'Profile' object has no attribute 'get_absolute_url'

My settings
I connect the users application:
image

users/models.py in app users :

class Profile(models.Model):

    user = models.OneToOneField(User, on_delete=models.CASCADE)
    bio = models.TextField(max_length=500, blank=True)
    avatar_rand = models.ImageField (default=random_image)

    def __str__(self):
        return f'{self.user.username} Profile'

users/apps.py:

from django.apps import AppConfig


class UsersConfig(AppConfig):
    name = 'users'
    verbose_name = 'Users Profile'

    def ready (self):
        import users.signals

What am I doing wrong, tell pls?

@ogurec-ogurec ogurec-ogurec added the bug Something isn't working label Dec 21, 2023
@ChathuraGH
Copy link

ChathuraGH commented Dec 21, 2023

You should have a 'get_absolute_url' function inside profile model returning the profile user of the user. (same like __str__ function. )
This url should be the profile url. You should generate this url inside this function.
def get_absolute_url(self): url="/profile" + str(self.id) return url
About is some common code. Change it to suite your profile path.
And also, if you solved it, say it in the comments and close this issues.

@ogurec-ogurec
Copy link
Author

@ChathuraGH thanks for the answer, I added in functuion:

   def get_absolute_url(self):
        url = "/" + self.user.username
        return url

and now the comments page works for me (and the links too). Thaks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants