#Can't display db data

20 messages · Page 1 of 1 (latest)

shy lion
#

I'm working on a Django project with a custom user model called CustomUser, which extends AbstractUser. I also have a Request model that has a foreign key to CustomUser.
Currently, queries to the CustomUser model are working fine — I can retrieve and display user data without issues. However, queries to the Request model are not working as expected . Specifically, when trying to filter requests by user (e.g., Request.objects.filter(user=user)), it seems like no data is returned, even though there are entries in the database.

timid patrol
#

```py

code

```

shy lion
#
class Request(models.Model):
    REQUEST_TYPES = [
        ('repair', 'Ремонт'),
        ('elevator', 'Проблемы с лифтом'),
        ('heating', 'Отопление'),
        ('changes', 'Замены'),
        ('quality', 'Качество ремонта'),
        ('warranty_issue', 'Гарантийные случаи'),
        ('permits', 'Разрешения'),
        ('other', 'Другое'),
    ]

    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name="Пользователь")
    street = models.CharField(max_length=255)
    house_number = models.CharField(max_length=20)
    entrance = models.CharField(max_length=10, blank=True)
    floor = models.CharField(max_length=10, blank=True)
    apartment = models.CharField(max_length=10, blank=True)
    request_type = models.CharField(max_length=20, choices=REQUEST_TYPES)
    description = models.TextField()
    status = models.CharField(max_length=50, default="Ожидает рассмотрения")

    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.get_request_type_display()} - {self.street}, {self.house_number}"

ty

timid patrol
#

you did modify settings.AUTH_USER_MODEL to point to your new custom model?

shy lion
#

yep, i did

timid patrol
#

mid-project or right from the start? seems to be more problematic mid-project

shy lion
#

i'ts mid project

#

i already have register and login working and now i'm trying to simply display a table with a filter

#

it seems like i can't retrieve any data from that table

timid patrol
#

This change can’t be done automatically and requires manually fixing your schema, moving your data from the old user table, and possibly manually reapplying some migrations. See #25313 for an outline of the steps.
https://code.djangoproject.com/ticket/25313

#

I'd assume your Request instances are still pointing to User IDs instead of CustomUser IDs and you'll have to find a way to map/fix those in a data migration possibly (?).

shy lion
#

should i just delete and remigrate the db?

timid patrol
#

if you can throw it all away, that's likely the simplest fix. that would include all current migrations I believe, you'd have to start those from scratch to satisfy the limitation of having a custom settings.AUTH_USER_MODEL

shy lion
#

got it, ty

timid patrol
#

🙏

shy lion
#

It doesn't seem to work. I've deleted the database and all migrations, but nothing changed. You said it might be because I use CustomUser and it's pointing to another user ID. How can I check if that's the case? I don't have any other tables with user information.

#

I found solution, it was my stupid ass using css wrong, anyway thx for help

regal veldt
#

Good works