Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
import uuid
from django.core import validators
from django.db import models
from django.db.models.base import Model
from django.db.models.deletion import SET, SET_NULL
from django.db.models.fields.related import ManyToManyField, OneToOneField

class Author(models.Model):

    class Meta:
        verbose_name = 'Автор'
        verbose_name_plural = 'Авторы'
        ordering = ['id']
        unique_together = ('name','age')

    TYPES = (
       ('a','foreign'),
       ('b','domestic'),
       ('c','other')
    )

    id = models.UUIDField(primary_key=True,db_index=True, default=uuid.uuid4)
    name = models.CharField(
        verbose_name='Имя автора',
        max_length=200,
        validators=[validators.RegexValidator(regex='^.*en$',message='Wrong')]
        )
    age = models.PositiveBigIntegerField(verbose_name='Возраст автора')
    email = models.EmailField(verbose_name='Почта автора')
    lit_tupe = models.CharField(max_length=1, verbose_name='Тип литиратуры',choices=TYPES, default='a')

    def __str__(self):
        return self.name

    
class Book(models.Model):

    class Meta:
        verbose_name = 'Книга'
        verbose_name_plural = 'Книги'
        get_latest_by = 'published'

    title = models.CharField(max_length=200)
    descripting = models.TextField()
    page_num = models.PositiveIntegerField()    
    published = models.DateTimeField(auto_now_add=True)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)


    def __str__(self):
      return self.title


class ExtUser(models.Model):

    desc = models.CharField(max_length=200)
    is_loggen = models.BooleanField(default=True)
    user = OneToOneField(User, on_delete=SET_NULL, null=True)

    def __str__(self):
        return self.desc

class Product(models.Model):

    name = models.CharField(max_length=200)

    def __str__(self):
        return self.name

class Store(models.Model):

    name = models.CharField(max_length=200)
    products = ManyToManyField(Product, related_name='stores')

    def __str__(self):
        return self.name


"C:\djangoo\web_lib\models.py ", строка 59, в ExtUser user = OneToOneField(User, on_delete=SET_NULL, null= True) Ошибка имени: имя "Пользователь" не определено

What I have tried:

I'm learning by video, I don't understand the code well, yes, it's clear to me that the user has not defined, but the elements are protected in the database, now I need this error to disappear
Posted
Updated 18-Nov-22 4:43am
v4
Comments
CHill60 17-Nov-22 9:29am    
This is not a good question - we can't help you if we can't work out what you are asking for.
What do you mean by "highlighted" and why is it important
Also - this is an English language site. Please translate your comments to English before posting. I will do that for you in this instance
Eva Smirnova 17-Nov-22 9:48am    
How can I upload a screenshot here?
Richard Deeming 17-Nov-22 10:10am    
You can't. And to be honest, if you can't describe the problem without resorting to a screenshot, then it's unlikely you can describe it in enough detail for anyone to help you.
Eva Smirnova 17-Nov-22 10:29am    
If I'm a beginner, how can I explain clearly? I can show what I want to do, you have a very poor resource and require a lot of work.
Richard MacCutchan 17-Nov-22 10:57am    
How are you viewing the file and exactly what is (not) showing for the imports? I have just checked on my system and viewing the file in Visual Studio Code, everything looks normal.

1 solution

You have the following class in your models ...
Python
class ExtUser(models.Model):

    desc = models.CharField(max_length=200)
    is_loggen = models.BooleanField(default=True)
    user = OneToOneField(User, on_delete=SET_NULL, null=True)

... and you declare the user as relating to the User class. But you do not have a User class in your models. So either something is missing from the tutorial you are following, or you skipped a step by mistake.

There is a good django tutorial at Writing your first Django app, part 1 | Django documentation | Django[^] which I recommend.
 
Share this answer
 
Comments
Eva Smirnova 20-Nov-22 0:35am    
<ya-tr-span data-index="250-0" data-translated="true" data-source-lang="en" data-target-lang="ru" data-value="По вашему учебнику ничего понять не возможно, у меня там 34 задачи, как же так? " data-translation="По вашему учебнику ничего понять не возможно, у меня там 34 задачи, как же так? " data-ch="0" data-type="trSpan" data-selected="false">По вашему учебнику ничего понять не возможно, у меня там 34 задачи, как же так? <ya-tr-span data-index="250-1" data-translated="true" data-source-lang="en" data-target-lang="ru" data-value="А ваш учебник ничему хорошему не учит, и подробно не объясняет, а значит пустая трата времени, разбирать вообще нечего. " data-translation="А ваш учебник ничему хорошему не учит, и подробно не объясняет, а значит пустая трата времени, разбирать вообще нечего. " data-ch="0" data-type="trSpan">А ваш учебник ничему хорошему не учит, и подробно не объясняет, а значит пустая трата времени, разбирать вообще нечего. <ya-tr-span data-index="250-2" data-translated="true" data-source-lang="en" data-target-lang="ru" data-value="Если я показал свой код и там была только одна ошибка, то в вашем коде их 34))) и никто не знает как их решить, или вы можете порекомендовать действительно хороший учебник, где все реально объяснено?" data-translation="Если я показал свой код и там была только одна ошибка, то в вашем коде их 34))) и никто не знает как их решить, или вы можете порекомендовать действительно хороший учебник, где все реально объяснено?" data-ch="0" data-type="trSpan" data-selected="false">Если я показал свой код и там была только одна ошибка, то в вашем коде их 34))) и никто не знает как их решить, или вы можете порекомендовать действительно хороший учебник, где все реально объяснено?
Here is your code from the third lesson. What can you understand there?
from django.http import HttpResponse

def index(request):
return HttpResponse("Hello,world.You're at the polls index")

def (request, question_id):
return HttpResponse("You're looking at question %s". % question_id)
def (reguest, question_id):
response = "You're looking at the results of question %s".
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse("You're vooting on question %s". % question_id)
Richard MacCutchan 20-Nov-22 2:43am    
Sorry, I have no idea what this message is supposed to mean.
Eva Smirnova 20-Nov-22 9:21am    
Yes, it’s understandable, you all answer like that when you understand that your advice doesn’t work, if you don’t know how to explain the error of my code, please say I don’t know it’s immediately clear, and you begin to advise textbooks in which the code is visible every other time, there the site of the curve or something, in general, as always, there is no sense from such resources.
Richard MacCutchan 20-Nov-22 9:39am    
I am sorry, but you have posted a message that is mainly in Russian, which few people on this site understand. This is followed by some lines of code without any context explanation of what they refer to or what problem they cause. So what exactly happened when you did follow the advice I gave you?
Eva Smirnova 20-Nov-22 9:53am    
Yes, I tried to write code according to your textbook, but they don’t explain where other characters come from and what they are for, in my understanding, such a textbook should not be taught by a scientist, since it’s impossible to understand such a stupid code, so I have it in my code a lot of mistakes for which I don’t know the answers, for a start, these books taught me to make out the mistakes better, and that was more useful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900