Radi85/Comment

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

Closed this issue ยท 2 comments

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?

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.

@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!