R
R
RandomProgrammer2021-07-27 11:17:50
Django
RandomProgrammer, 2021-07-27 11:17:50

Django not finding model?

I have two models:

class User(models.Model):
    ...
    subscriptions = models.ManyToManyField(Channel, verbose_name="подписки", related_name='subscribers')


class Channel(models.Model):
    ...
    authors = models.ManyToManyField(User, verbose_name="автор(ы) канала", related_name="channels")
    ...

When I try to run makemigrations, it gives an error:
NameError: name 'Channel' is not defined
I'm assuming it's because the model Channelis below. But if you move it higher, then the model is not found User. Offers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-07-27
@RandomProgrammer

I suggest reading the documentation, where this situation is mentioned and the solution is described - to pass the string name of the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question